Appstore作为iOS6中的模态视图

iTa*_*rek 22 xcode app-store ios6

我注意到当用户点击iOS6邮件应用程序中应用程序商店链接时,邮件会打开一个代表应用程序商店的模态视图,而不是像之前版本中那样切换到App Store应用程序.

Apple是否提供对此功能的访问权限,或者它是否为其集成程序所独有?


注意:如果你有iOS 6并想要测试它,只需打开appstore和电子邮件应用程序给自己.

Max*_*iel 44

我将此方法作为类别添加到UIViewController,但您可以根据自己的需要重新调整它.应用商店ID是应用商店网址中的大号码.确保导入StoreKit框架和头文件!

@import StoreKit;

- (void)presentAppStoreForID:(NSNumber *)appStoreID withDelegate:(id<SKStoreProductViewControllerDelegate>)delegate
{
    if(NSClassFromString(@"SKStoreProductViewController")) { // Checks for iOS 6 feature.

        SKStoreProductViewController *storeController = [[SKStoreProductViewController alloc] init];
        storeController.delegate = delegate; // productViewControllerDidFinish

        // Example App Store ID (e.g. for Words With Friends)
        // @322852954

        [storeController loadProductWithParameters:@{ SKStoreProductParameterITunesItemIdentifier: appStoreID }
                                   completionBlock:^(BOOL result, NSError *error) {
            if (result) {
                [self presentViewController:storeController animated:YES completion:nil];
            } else {
                [[[UIAlertView alloc] initWithTitle:@"Uh oh!" message:@"There was a problem opening the app store" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil] show];
            }
        }];

    } else { // Before iOS 6, we can only open the App Store URL
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/app/id%@",appStoreID]]];
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 自从我回答以来,有几个人看过这个.为了添加更多细节,我强烈建议您在调用loadProductWithParameters之前启动UIActivityIndi​​catorView - 它可能非常慢.另外,如果你只有appStore URL,你可以把你的代码用来提取这个方法中的appStoreID号码(我只是将它们分开,因为我们的模型碰巧已经单独存储它们).最后,确保将Alert视图文本替换为与您的应用程序相关的内容. (3认同)
  • 谢谢,您知道是否有办法将该方法与app store联盟计划一起使用?因为似乎无法将pratnerID和siteID传递给appstore (2认同)