当前苹果已经禁止了,通过IOS应用直接跳转APP下载链接的方法。但是仍然可以使用另外一种方法直接跳转AppStore。
这种方法需要增加一个类库StoreKit.framework。 这里使用这功能是为用户提供更新,下面说下我实现这个功能的详细步骤。
一、增加一个网页到服务器上去,title增加你当前APP的版本号。
二、在viewDidLoad里面增加UIWebView加载服务器上增加的网页,并获取当前版本号
1:下面是是uiwebview 加载网页的代码
-(void)viewDidLoad { [super viewDidLoad]; BeeUIWebView* getVersionWebView=[[BeeUIWebView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)]; getVersionWebView.backgroundColor = [UIColor redColor]; getVersionWebView.scalesPageToFit =YES; NSString *pagePath=[NSString stringWithFormat:@"http://www.jmfww.com/Mobile/iosVersionInfo.html"]; NSURL *url =[[NSURL alloc] initWithString: pagePath]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; getVersionWebView.delegate=self; [getVersionWebView loadRequest:request]; }
2:uiwebview代理
- (void)webViewDidFinishLoad:(UIWebView *)webView { NSString *value= [webView stringByEvaluatingJavaScriptFromString:@"document.title"]; NSArray *VersionAndStoreLoadUrlArray= [value componentsSeparatedByString:@","]; NSString *Version=[VersionAndStoreLoadUrlArray objectAtIndex:1]; NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; // app名称 // NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"]; // app版本 NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"]; if (![app_Version isEqualToString:Version]) { showMessage(@"请前往AppStore下载最新版本"); [self openAppStore:@"932016124"]; } }
二、SKStoreProductViewController
//首先引入SKStoreProductViewController代理SKStoreProductViewControllerDelegate //跳转APPSTORE的方法 -(void)openAppStore:(NSString *)appId{ SKStoreProductViewController *storeProducVC= [[SKStoreProductViewController alloc]init]; storeProducVC.delegate=self; NSDictionary *dict=[NSDictionary dictionaryWithObject:appId forKey:SKStoreProductParameterITunesItemIdentifier]; [storeProducVC loadProductWithParameters:dict completionBlock:^(BOOL result, NSError * _Nullable error) { if (result) { [self presentViewController:storeProducVC animated:YES completion:nil]; } }]; } //SKStoreProductViewController返回代理 -(void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController { [viewController dismissViewControllerAnimated:YES completion:nil]; }