如果 iPhone 上没有安装应用程序,我想打开 Appstore。例如。我想从我的应用程序打开 facebook。我就是这样做的
UIApplication *ourApplication = [UIApplication sharedApplication];
NSString *ourPath = @"fb://profile/1234";
NSURL *ourURL = [NSURL URLWithString:ourPath];
[ourApplication openURL:ourURL];
但是如果设备上没有安装 facebook 应用程序,我会收到这样的错误:
LaunchServices: ERROR: There is no registered handler for URL scheme fb
在这种情况下,我想将用户带到 AppStore 上的 facebook 应用程序。我知道我可以这样做:
NSString *stringURL = @"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=294409923&mt=8";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
但是我怎么知道什么是 Facebook AppStore id?
最佳答案
检查 openURL:
的返回值。如果它返回 NO
,则为所需应用创建一个 SKStoreProductViewController
设置。
if (![ourApplication openURL:ourURL]) {
// can't launch app for 'fb' scheme
// Create and display SKStoreProductViewController
}
如果您不想使用 SKStoreProductViewController
,请改用问题末尾的 openURL
代码。
关于ios - 如果应用程序未安装在 iOS 上,请打开 AppStore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32893884/