Sumit Chauhan
Sumit Chauhan

Reputation: 73

URL Scheme not working in iOS9

I am working on an app in which a user confirmation mail sent to user email. I am able to receive the mail in this format"http://www.sample.com//Register.aspx?xxx(with parameters)". Now on click of this mail i have to launch the register page in iOS9.

Note: if i type Register.aspx:// in safari app is opening but not from email URL.

I have done the following things in info.plist and in code 1.info.plist

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>Register.aspx</string>
            </array>
        </dict>
    </array> 
<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>Register.aspx</string>
    </array>

2.in app delegate i used:

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {

    BOOL canBeOpened = [[UIApplication sharedApplication]
                        canOpenURL:[NSURL URLWithString:@"Register.aspx://"]];

    if (canBeOpened) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Test Message"
                                                        message:@"This is a url scheme"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];

    }
    else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Test Message"
                                                        message:@"This is not a url scheme"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];

    }
}

Upvotes: 2

Views: 5991

Answers (2)

Vijay Kachhadiya
Vijay Kachhadiya

Reputation: 376

iOS 9 has made a small change to the handling of URL scheme. You must whitelist the url's that your app will call out to using the LSApplicationQueriesSchemes key in your Info.plist.

Please check this link : http://awkwardhare.com/post/121196006730/quick-take-on-ios-9-url-scheme-changes

Upvotes: 4

R. Hatherall
R. Hatherall

Reputation: 1191

You are registering the wrong part of the URL as the scheme. The example you provide has a standard URL scheme of http.

The bit of the URL before the first colon is the scheme (http or https typically). To use a custom scheme you need to make up a new scheme for the URL and output that URL in your email e.g.:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>mycoolapp</string>
        </array>
    </dict>
</array> 
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>mycoolapp</string>
</array>

Needs an email with a URL like:

mycoolapp://www.sample.com/Register.aspx

Upvotes: 4

Related Questions