-
Notifications
You must be signed in to change notification settings - Fork 6
PredixAppWindowProtocol
The PredixAppWindowProtocol is a protocol that must be implemented by UI components in order to work with the Predix Mobility SDK. The protocol is used by the SDK to control which elements are on-screen, and how the user interacts with those elements:
In the examples below, assume the implementing object is a UIViewController that contains three subviews: a UIWebView (webView), a UIActivityIndicatorView (spinner), and a UILabel (spinnerLabel)
Methods:
loadURL
Called when the SDK needs to display something. This method takes the following parameters:
- URL: an NSURL object. This will generally be the URL of the app package, a URL of an authentication website, or URL of a webpage bundled with the app.
- parameters: dictionary object associated with the app package
- onComplete: a Swift closure/ObjC block that should be called when the URL has successfully been loaded
Swift example implementation:
func loadURL(URL: NSURL, parameters: [NSObject : AnyObject]?, onComplete: (()->())?)
{
if let onComplete = onComplete
{
self.webViewFinishedLoad = onComplete
}
self.webView.loadRequest(NSURLRequest(URL:URL))
}
func webViewDidFinishLoad(webView: UIWebView)
{
if let webViewFinishedLoad = self.webViewFinishedLoad
{
webViewFinishedLoad()
self.webViewFinishedLoad = nil
}
}
ObjC example implementation:
-(void) loadURL:(NSURL *)URL parameters:(NSDictionary *)parameters onComplete:(void (^)(void))onComplete
{
self.webViewFinishedLoad = onComplete;
[self.webView loadRequest:[NSURLRequest requestWithURL: URL]];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
if (self.webViewFinishedLoad)
{
self.webViewFinishedLoad();
self.webViewFinishedLoad = nil;
}
}
updateWaitState
Called when the SDK wishes to display a spinner or other user wait indicator. This method takes the following parameters:
- state: a WaitState enumeration: either Waiting, or NotWaiting. Used to determine if the wait indicator should be shown or hidden.
- message: an optional string to display
Swift example implementation:
func updateWaitState(state: WaitState, message: String?)
{
switch state
{
case .NotWaiting :
self.spinner.stopAnimating()
self.spinner.hidden = true
self.spinnerLabel.text = nil
self.spinnerLabel.hidden = true
case .Waiting :
self.spinner.hidden = false
self.spinnerLabel.hidden = false
self.spinner.startAnimating()
self.spinnerLabel.text = message
}
}
ObjC example implementation:
-(void) updateWaitState:(enum WaitState)state message:(NSString *)message
{
if (state == WaitStateWaiting)
{
self.spinner.hidden = NO;
self.spinnerLabel.hidden = NO;
[self.spinner startAnimating];
self.spinnerLabel.text = message;
}
else
{
[self.spinner stopAnimating];
self.spinner.hidden = YES;
self.spinnerLabel.hidden = YES;
self.spinnerLabel.text = nil;
}
}
waitState Called when the SDK needs to determine the current wait indicator state. Takes no parameters, but should return a WaitStateReturn object, which has the following properties:
- state: a WaitState enumeration: either Waiting, or NotWaiting. Indicating if the wait indicator is being shown or hidden.
- message: an optional string that is being displayed with the wait indicator
Swift example implementation:
func waitState()->(WaitStateReturn)
{
return WaitStateReturn(state: self.spinner.hidden ? .NotWaiting : .Waiting, message: self.spinnerLabel.text)
}
ObjC example implementation:
-(WaitStateReturn*) waitState
{
WaitState state = WaitStateWaiting;
if (self.spinner.hidden)
{
state = WaitStateNotWaiting;
}
return [[WaitStateReturn alloc] initWithState:state message:self.spinnerLabel.text];
}
receiveAppNotification An optional method, used with the Notify Service to notify consuming applications of a notification event. This method takes a single parameter:
- script: The script string provided to the Notify Service when the notification is registered.
It is expected this script string will be executed in the web view when receiveAppNotification is called.
Swift example implementation:
func receiveAppNotification(script: String)
{
self.webView.stringByEvaluatingJavaScriptFromString(script)
}
ObjC example implementation:
-(void) receiveAppNotification:(NSString *)script
{
[self.webView stringByEvaluatingJavaScriptFromString:script];
}
Intro *Home
Services
- Authentication
- Boot
- Command
- Connectivity
- Data Access High-level
- Data Access Low-level
- Logging
- Notify
- OpenURL
- Secure Storage
- TouchId
- User Information
- User Settings
- Version
- Window
iOS SDK
- General
- Posted Notifications
- Remote Notifications
- Classes
- PredixMobilityConfiguration
- PredixMobilityManager
- Protocols
- PredixAppWindowProtocol
iOS Examples
Java Examples
General
[//]: (Enabling Sync Logging)