为什么我不能用 ios 9 打开 facebook 和 twitter 应用程序
why can't I open facebook and twitter app with ios 9
在 ios9 出现之前,我使用以下代码在按钮 clicked.using 时使用我的应用程序打开 facebook 应用程序 如果 phone 有 facebook 应用程序,它会打开 facebook 应用程序,并且,如果不是,它会打开 safari browser.same 因为 twitter.this 是我的代码。
- (IBAction)facebookButton:(id)sender {
NSURL *facebookUrl = [NSURL URLWithString:@"fb://profile/number"];
if ([[UIApplication sharedApplication] canOpenURL:facebookUrl]) {
[[UIApplication sharedApplication] openURL:facebookUrl];
}
else{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.facebook.com/number"]];
}
}
- (IBAction)twitterButton:(id)sender {
NSURL *twitterUrl = [NSURL URLWithString:@"twitter://profile/"];
if ([[UIApplication sharedApplication] canOpenURL:twitterUrl]) {
[[UIApplication sharedApplication] openURL:twitterUrl];
}
else{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.twitter.com/"]];
}
}
这很好用,之前 iOS 9.but 现在如果应用程序存在与否,它只打开 safari.help 我用这个
我们必须在 info.plist
中添加以下内容
来自关于 canOpenURL:
方法的 Apple 文档:
If your app is linked on or after iOS 9.0, you must declare the URL
schemes you want to pass to this method. Do this by using the
LSApplicationQueriesSchemes array in your Xcode project’s Info.plist
file. For each URL scheme you want your app to use with this method,
add it as a string in this array.
If your (iOS 9.0 or later) app calls this method using a scheme you
have not declared, the method returns NO, whether or not an
appropriate app for the scheme is installed on the device.
Unlike this method, the openURL: method is not constrained by the
LSApplicationQueriesSchemes requirement: If an app that handles a
scheme is installed on the device, the openURL: method works, whether
or not you have declared the scheme.
Apple 将此更改添加到 API,因为 canOpenURL:
方法通常用于接收有关安装在用户设备上的应用程序的信息,而无需实际 openURL:
调用。
问题可以通过以下方式解决:
将 "fb" 和 "twitter" URL 方案添加到 Info.plist;
的 LSApplicationQueriesSchemes 数组中
openURL:
方法 returns NO 如果 URL 没有成功打开。您可以通过以下方式重写代码以避免 canOpenURL:
调用:
if (![[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"fb://profile/number"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.facebook.com/number"]];
}
查看以类似方式工作的通用链接 - 打开应用程序,如果它在设备上可用,否则 URL 在 Safari 中打开。
自定义深层链接模式不再适用于 iOS9。您需要使用通用链接。请参阅 this 指南。
在 ios9 出现之前,我使用以下代码在按钮 clicked.using 时使用我的应用程序打开 facebook 应用程序 如果 phone 有 facebook 应用程序,它会打开 facebook 应用程序,并且,如果不是,它会打开 safari browser.same 因为 twitter.this 是我的代码。
- (IBAction)facebookButton:(id)sender {
NSURL *facebookUrl = [NSURL URLWithString:@"fb://profile/number"];
if ([[UIApplication sharedApplication] canOpenURL:facebookUrl]) {
[[UIApplication sharedApplication] openURL:facebookUrl];
}
else{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.facebook.com/number"]];
}
}
- (IBAction)twitterButton:(id)sender {
NSURL *twitterUrl = [NSURL URLWithString:@"twitter://profile/"];
if ([[UIApplication sharedApplication] canOpenURL:twitterUrl]) {
[[UIApplication sharedApplication] openURL:twitterUrl];
}
else{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.twitter.com/"]];
}
}
这很好用,之前 iOS 9.but 现在如果应用程序存在与否,它只打开 safari.help 我用这个
我们必须在 info.plist
来自关于 canOpenURL:
方法的 Apple 文档:
If your app is linked on or after iOS 9.0, you must declare the URL schemes you want to pass to this method. Do this by using the LSApplicationQueriesSchemes array in your Xcode project’s Info.plist file. For each URL scheme you want your app to use with this method, add it as a string in this array.
If your (iOS 9.0 or later) app calls this method using a scheme you have not declared, the method returns NO, whether or not an appropriate app for the scheme is installed on the device.
Unlike this method, the openURL: method is not constrained by the LSApplicationQueriesSchemes requirement: If an app that handles a scheme is installed on the device, the openURL: method works, whether or not you have declared the scheme.
Apple 将此更改添加到 API,因为 canOpenURL:
方法通常用于接收有关安装在用户设备上的应用程序的信息,而无需实际 openURL:
调用。
问题可以通过以下方式解决:
将 "fb" 和 "twitter" URL 方案添加到 Info.plist;
的 LSApplicationQueriesSchemes 数组中
openURL:
方法 returns NO 如果 URL 没有成功打开。您可以通过以下方式重写代码以避免canOpenURL:
调用:if (![[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"fb://profile/number"]]) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.facebook.com/number"]]; }
查看以类似方式工作的通用链接 - 打开应用程序,如果它在设备上可用,否则 URL 在 Safari 中打开。
自定义深层链接模式不再适用于 iOS9。您需要使用通用链接。请参阅 this 指南。