The Jabber Guest Demo app is configured to handle the Jabber Guest scheme. You can have your app handle your own custom URL scheme. To get a basic understanding of how to implement a customer URL scheme, read Implementing Custom URL Schemes.
The following code can be placed in an app to open a Jabber Guest URL that is using the default scheme. The Jabber Guest Demo app can handle this URL. If you have your own customer URL scheme and app to handle it, you can use your own scheme instead.
The method assumes that a serverName and URI property holding the appropiate values are available.
- (void)launchJabberGuest:(id)sender {
NSString * serverName = self.serverName;
NSString * encodedURI = [self.uri stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL * url = [NSURL URLWithString:[@"jabberguest://" stringByAppendingFormat:@"%@?uri=%@", serverName, encodedURI]];
UIApplication * thisApp = [UIApplication sharedApplication];
if ([thisApp canOpenURL:url]) {
[thisApp openURL:url];
} else {
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"No JabberGuest App Found"
message:@"The JabberGuest App is not installed."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
To have your app handle the custom URL, you need modify your applications Info.plist and implement the openURL delegate.
If more than one third-party app registers to handle the same URL scheme, there is currently no process for determining which app will be given that scheme.
If you are using the high-level CJGuestCallViewController object, in your application's delegate implement the following code. The method configureFromURL: will pull the host name and the URI to call from the URL.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
CJGuestCallViewController * jabberGuest = [[CJGuestCallViewController alloc] init];
[jabberGuest configureFromURL:url];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:jabberGuest];
[self.window setRootViewController:nc];
return YES;
}
If you want to control the handling of the URL in your code, or you are not using the CJGuestCallViewController, the configureFromURL: method is implemented in the CJGuestCallViewController as such.
- (void)configureFromURL:(NSURL *)url
{
self.serverName = [url host];
NSDictionary *query = [JabberGuest parseQueryString:[url query]];
self.toURI = [query objectForKey:@"uri"];
}