简体   繁体   中英

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

    }
}

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 eg:

<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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM