URL Schemes

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.

Opening a Jabber Guest URL

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];
    }
}

Implementing a Custom URL Scheme

To have your app handle the custom URL, you need modify your applications Info.plist and implement the openURL delegate.

Adding Your Scheme to Info.plist

  1. Open your apps Info.plist file.
  2. Right-click in the editor and select Add Row.

    Add URL Scheme Row

  3. From the drop-down list select URL types.
  4. Open URL types, open Item 0, and add a unique name for your URL scheme to the value of URL Identifier. Example: com.yourcompany.JabberGuest
  5. Click the + button next to the URL Identifier key.
  6. From the drop-down list select URL Schemes.
  7. Open URL Schemes, open Item 0, and add the name of your URL scheme. Example: yourcompany-JabberGuest or yourcompany.JabberGuest
  8. URL Types

  9. Choose a unique URL scheme name. Apple documentation states the following:
  10. 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.

The openURL delegate

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"];
}