【问题标题】:Open AppStore if app is not installed on iOS如果 iOS 上未安装应用程序,请打开 AppStore
【发布时间】:2015-12-29 21:06:56
【问题描述】:

如果 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 是什么?

【问题讨论】:

    标签: ios app-store


    【解决方案1】:

    检查openURL:的返回值。如果它返回NO,则为所需应用创建SKStoreProductViewController 设置。

    if (![ourApplication openURL:ourURL]) {
        // can't launch app for 'fb' scheme
        // Create and display SKStoreProductViewController
    }
    

    如果您不想使用SKStoreProductViewController,请改用问题末尾的openURL 代码。

    【讨论】:

      猜你喜欢
      • 2015-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-29
      • 2017-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多