当前位置: 移动技术网 > 移动技术>移动开发>IOS > iOS如何跳转到App Store下载评分页面示例代码

iOS如何跳转到App Store下载评分页面示例代码

2019年07月24日  | 移动技术网移动技术  | 我要评论

前言

目前很多应用是要求点击事件直接跳转到app store,最近工作中就遇到了一个跳转 app store 评分或者下载更新的功能,网上查到很多跳转方法,这里记录一下,下面话不多说了,来一起看看详细的介绍吧。

主要跳转方法有两种

  • 使用官方 storekit.framework 框架
  • 应用间跳转直接跳到 app store 应用,并携带自己 app 的 appid。

使用官方框架

苹果提供了storekit.framework框架,工程中可以导入这个框架的主头文件

#import <storekit/storekit.h>,

也可以直接导入

#import<storekit/skstoreproductviewcontroller.h >,

添加代理并实现代理方法<skstoreproductviewcontrollerdelegate>

示例代码

/**
 应用内跳转到app store页
 */
- (ibaction)jump:(id)sender { 
 nsstring *appid = @"1066602104"; 
 // 创建对象
 skstoreproductviewcontroller *storevc = [[skstoreproductviewcontroller alloc] init];
 // 设置代理
 storevc.delegate = self;
 // 初始化参数
 nsdictionary *dict = [nsdictionary dictionarywithobject:appid forkey:skstoreproductparameteritunesitemidentifier];
 // 跳转app store页
 [storevc loadproductwithparameters:dict completionblock:^(bool result, nserror * _nullable error) {
  if (error) {
   nslog(@"错误信息:%@",error.userinfo);
  }
  else
  {
   // 弹出模态视图
   [self presentviewcontroller:storevc animated:yes completion:nil];
  }
 }]; 
}

#pragma mark -- skstoreproductviewcontrollerdelegate
/**
 skstoreproductviewcontrollerdelegate 方法,选择完成之后的处理
 @param viewcontroller skstoreproductviewcontroller
 */
- (void)productviewcontrollerdidfinish:(skstoreproductviewcontroller *)viewcontroller
{
 nslog(@"将要退出 app store 页面了");
 [viewcontroller dismissviewcontrolleranimated:yes completion:^{
  nslog(@"已经退出 app store 页面完成了");
 }];
}

应用内跳转直接到 app store 页面

此方法使用 [[uiapplication sharedapplication] openurl:url];打开链接的方式跳转到app store。

此方法主要是需要拿到自己要跳转 app 的 app store 的 url 地址

/**
 直接跳转
 */
- (ibaction)justjumptootherpage:(id)sender {
 // 应用地址
 nsstring *appstr = @"https://itunes.apple.com/app/apple-store/id1317248738?pt=118536605&ct=web&mt=8";
 // 跳转
 nsdictionary *options = @{uiapplicationopenurloptionuniversallinksonly
        :@(yes)};
 [[uiapplication sharedapplication] openurl:[nsurl urlwithstring:appstr] options:options completionhandler:^(bool success) {
  nslog(@"将要进入 app store 页面了");
 }]; 
}

- (ibaction)jumptoscorepage
{  
 nslog(@"将要进入 app store 评分页面了"); 
 // 评分页面地址
 nsstring *scorestr = [nsstring stringwithformat:@"https://itunes.apple.com/webobjects/mzstore.woa/wa/viewcontentsuserreviews?id=%@&pagenumber=0&sortordering=2&type=purple+software&mt=8",appid];  
 // 判断系统用对应方法
 if ( @available(ios 10 , * )) {
  [[uiapplication sharedapplication] openurl:[nsurl urlwithstring:scorestr] options:options completionhandler:^(bool success) {  
   nslog(@"已经进入 app store 页面了");
  }];
 } else {
  [[uiapplication sharedapplication] openurl:[nsurl urlwithstring:appstr]];
 }
}

【注意】 跳转 app store 需要真机运行

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对移动技术网的支持。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网