如果 iOS 上未安装应用,请打开 AppStore
Open AppStore if app is not installed on iOS
如果 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:
的 return 值。如果它 returns NO
,则为所需应用创建 SKStoreProductViewController
设置。
if (![ourApplication openURL:ourURL]) {
// can't launch app for 'fb' scheme
// Create and display SKStoreProductViewController
}
如果您不想使用 SKStoreProductViewController
,请改用问题末尾的 openURL
代码。
如果 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:
的 return 值。如果它 returns NO
,则为所需应用创建 SKStoreProductViewController
设置。
if (![ourApplication openURL:ourURL]) {
// can't launch app for 'fb' scheme
// Create and display SKStoreProductViewController
}
如果您不想使用 SKStoreProductViewController
,请改用问题末尾的 openURL
代码。