最近要完成一个需求,在向用户提示更新警告框时,需要跳转到AppStore中应用的详细页面。
工具/原料
XCode6.4
方法/步骤
1、选择“Capabilities”选项卡
2、添加StoreKit框架,只需开启“In-AppPurchase"。
3、修改指定的ViewContro盟敢势袂ller.h文件内容://*********************************忮氽阝另*******#import<UIKit/UIKit.h>#import<StoreKit/StoreKit.h>@interfaceViewController:UIViewController<SKStoreProductViewControllerDelegate>-(void)openAppStore:(NSString*)appId;@end//*********************************************其中StoreKit/StoreKit.h是AppStore有关的头文件SKStoreProductViewControllerDelegate是AppStore有关的代理openAppStore是我们实现用来打开AppStore的函数,其中参数appId是应用的ID,这个ID可以从iTunesConnect中获得
4、实现SKStoreProductViewControllerDelegate委托的函数//****************************************-(void)productViewControllerDidFinish:(SKStoreProductViewController*)viewController{[viewControllerdismissViewControllerAnimated:YEScompletion:nil];}//****************************************
5、实现openAppStore函数//*************涯箨唁峦***************************-(void)openAppStore:(NSString*)锾攒揉敫appId{SKStoreProductViewController*storeProductVC=[[SKStoreProductViewControlleralloc]init];storeProductVC.delegate=self;NSDictionary*dict=[NSDictionarydictionaryWithObject:appIdforKey:SKStoreProductParameterITunesItemIdentifier];[storeProductVCloadProductWithParameters:dictcompletionBlock:^(BOOLresult,NSError*error){if(result){[selfpresentViewController:storeProductVCanimated:YEScompletion:nil];}}];}//****************************************
6、最后,你可以这样调用打开AppStore//****************************************[selfopenAppStore:@"324324234"];//****************************************