#### 不跳轉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具體效果圖:
注意:在測試和TestFlight環境下,是不能夠點擊提交的評論的。另外這個只是給出一個評價等級,具體評論內容還要用系統給出的Deeplink—— itunes.apple.com/app/idXXXXX…