从Safari中的Web应用程序中的链接打开iphone应用程序
我正试图通过safari中的链接打开我的原生iPhone应用程序。我已关注此链接创建一个url架构。我已将 appgo://
添加为我的网址架构,将com.xxxx.appgo添加为网址类型下的标识符。以下是我在safari网页中的链接:打开iPhone App
但是当我点击链接时,应用程序无法打开并且safari会生成错误警报:Safari无法进入页面,因为地址无效。
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.
我的包标识符:com.xxxxx.abc
注意:我的包标识符与URL类型中的标识符不同。这可能是一个问题吗?
my bundle identifier: com.xxxxx.abc Note: My bundle identifier is different from the identifier in URL types. Can that be an issue?
编辑:
我已将包标识符和网址标识符设为相同。我还在我的app delegate中添加了以下代码:
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;
}
我正在测试它我的iPad。我首先从xcode安装最新版本的应用程序,然后按主页按钮,然后打开safari中的链接。但是我仍然收到警报说Safari无法进入页面,因为地址无效。我在safari中的链接:
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>
在app delegate中实施
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;
}
编辑:
添加你的info.plist文件
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>