ios - 如果应用程序未安装在 iOS 上,请打开 AppStore

标签 ios app-store

如果 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/

相关文章:

ios - 我怎样才能提高性能

ios - 如何识别 AVPlayer 处于暂停状态并且用户正在清理

ios - Storyboard ui 元素不会出现在 Xcode 5 中

ios - 无法将类型 '(key: String, value: AnyObject)' 的值转换为预期的参数类型 '[String : AnyObject]'

ios - 消耗品IAP不能多次购买

javascript - 具有向 Apple AppStore 提交 HTML/JS 应用程序(例如 jQuery Mobile 和 PhoneGap)的经验

android - 适用于 Android 和 iOS 的通用 App Store 均可私下访问

ios - Xcode 4.6 中的 "po"命令第一次非常慢

ios - 如何停止应用程序商店要求下载早期版本

ios - 验证 iOS 应用程序时出现 com.apple.developer.associated-domains 问题