open an iphone app from a link in a web app in saf

2019-04-10 14:06发布

问题:

I am trying to open my native iPhone application from a link in safari. I have followed this link to create a url schema. I have added appgo:// as my url schema and com.xxxx.appgo as Identifier under URL Types. Following is my link in web page in safari: Open iPhone App But when I click on the link the app doesn't open up and safari produce an alert with error: Safari cannot enter the page as the address is invalid.

my bundle identifier: com.xxxxx.abc Note: My bundle identifier is different from the identifier in URL types. Can that be an issue?

Edit: I have made bundle identifier and url identifier same. I have also added following code in my app delegate:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
NSLog(@"application");
BOOL returnValue = NO;
NSString *urlString = [url absoluteString];
if([urlString hasPrefix:@"com.xxxx.appgo"]){
    returnValue = YES;
}
return returnValue;

}

I am testing it in my iPad. I first install the latest version of app from xcode and then press on home button and then open the link in safari. But I am still getting the alert saying the Safari cannot enter the page as address is invalid. My link in safari:

<a href="appgo://">Open iPhone App</a>

回答1:

Implement in app delegate

    - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
        BOOL returnValue = NO;
        NSString *urlString = [url absoluteString];
        if([urlString hasPrefix:@"appgo://"]){  
             returnValue = YES;
        }
       return returnValue;
    }

Edit: Add in your info.plist file

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string>com.xxxx.appgo</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>appgo</string>
                <string>yourSecondScheme</string>
            </array>
        </dict>
    </array>


回答2:

Yes. You bundle identifier must be same as the URL types in the plis file.

For more you can refere this link.

Hope this will be helpful to you.

All the best !!!