#### 不跳转App Store 应用内直接下载应用bash
SKStoreProductViewController 这个类须要了解下。app
/* View controller to display iTunes Store product information */
SK_EXTERN_CLASS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED @interface SKStoreProductViewController : UIViewController
复制代码
官方解释:用于展现iTunes Store 商品信息的类,继承自UIViewController。ide
1.导入头文件:#import <StoreKit/StoreKit.h>
测试
2.初始化类,设置代理SKStoreProductViewControllerDelegate
,展现VC。必须使用Present VC方式ui
SKStoreProductViewController *storeVC = [[SKStoreProductViewController alloc] init];
//设置代理 SKStoreProductViewControllerDelegate
storeVC.delegate = self;
[self presentViewController:storeVC animated:YES completion:nil];
复制代码
3.请求Store 信息。 必须在展现VC以后再请求spa
/** presentVC 以后再调取加载Store方法 官方备注:
// Load product view for the product with the given parameters. See below for parameters (SKStoreProductParameter*).
// Block is invoked when the load finishes.
*/
[storeVC loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier : @"1131090631"} completionBlock:^(BOOL result, NSError * _Nullable error) {
if (error) {
NSLog(@"error = %@", error);
}else {
NSLog(@"显示完成");
}
}];
复制代码
3.1.若是你不想整个界面就单单的弹出这个下载界面,还想在这加点本身的东西,也是能够自定义视图的。 改变SKStoreProductViewController的frame。代理
SKStoreProductViewController *storeVC = [[SKStoreProductViewController alloc] init];
storeVC.delegate = self;
NSDictionary *appDict = @{SKStoreProductParameterProductIdentifier : @"appid" };
[storeVC loadProductWithParameters:appDict completionBlock:^(BOOL result, NSError * _Nullable error) {
if (result) {
[self presentViewController:storeVC animated:YES completion:^{
//若是这里我想自定义一个相似于Banner的视图
UIImageView *bannerImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 260)];
bannerImage.image = [UIImage imageNamed:@""];
[storeVC.view.superview addSubview:bannerImage];
//修改展现App Store的frame
storeVC.view.frame = CGRectMake(0, 300, self.view.frame.size.width, self.view.frame.size.height - 260);
}];
}else if (error) {
NSLog(@"加载失败le");
}
}];
复制代码
具体请求的Paramters ,能够点进去看下具体是什么:code
// iTunes Store item identifier (NSNumber) of the product
SK_EXTERN NSString * const SKStoreProductParameterITunesItemIdentifier NS_AVAILABLE_IOS(6_0);
// SKU for the In-App Purchase product (NSString) to render at the top of the product page
SK_EXTERN NSString * const SKStoreProductParameterProductIdentifier NS_AVAILABLE_IOS(11_0);
// Analytics provider token (NSString)
SK_EXTERN NSString * const SKStoreProductParameterProviderToken NS_AVAILABLE_IOS(8_3);
// Advertising partner token (NSString)
SK_EXTERN NSString * const SKStoreProductParameterAdvertisingPartnerToken NS_AVAILABLE_IOS(9_3); NS_AVAILABLE_IOS(6_0);
// SKU for the In-App Purchase product (NSString) to render at the top of the product page
SK_EXTERN NSString * const SKStoreProductParameterProductIdentifier NS_AVAILABLE_IOS(11_0);
// iTunes Store affiliate token (NSString)
SK_EXTERN NSString * const SKStoreProductParameterAffiliateToken NS_AVAILABLE_IOS(8_0);
// iTunes Store affiliate campaign token (NSString)
SK_EXTERN NSString * const SKStoreProductParameterCampaignToken NS_AVAILABLE_IOS(8_0);
// Analytics provider token (NSString)
SK_EXTERN NSString * const SKStoreProductParameterProviderToken NS_AVAILABLE_IOS(8_3);
// Advertising partner token (NSString)
SK_EXTERN NSString * const SKStoreProductParameterAdvertisingPartnerToken NS_AVAILABLE_IOS(9_3);
复制代码
App Store 参数:SKStoreProductParameterITunesItemIdentifier
, 值就是的应用ID(纯数字便可,不要id)。eg: itunes.apple.com/cn/app/gear… 这里只取:1131090631.orm
4.实现代理方法, dismiss VCcdn
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
//点击完成或是下载更新完成的回调,dismiss掉VC
[viewController dismissViewControllerAnimated:YES completion:nil];
}
复制代码
至此,应用内下载更新应用完成。
貌似在iOS 12系统上请求比较慢.issue 这个方法没用系统跳转慢
能够点到这里看下<StoreKit/StoreKit.h>, 还有SKStoreReviewController.h
, SKProductStorePromotionController
具体能够研究下。
这个是apple在iOS10.3推出的新内容,在应用内给App评分。 这个方法一年以内最多使用三次,可是若是需求想让用户评论,感受一年三次这个限制太少了。 详情请看官方连接:来来来看看
请求评论,很是简单,就一句话便可,后续工做系统都给你完成了:
if ([[UIDevice currentDevice].systemVersion floatValue] > 10.3) {
if ([SKStoreReviewController respondsToSelector:@selector(requestReview)]) {
[SKStoreReviewController requestReview];
}
}
复制代码
UI具体效果图:
另外这个只是给出一个评价等级,具体评论内容还要用系统给出的Deeplink—— itunes.apple.com/app/idXXXXX…