應(yīng)用內(nèi)跳轉(zhuǎn)下載頁
使用StoreKit中的SKStoreProductViewController類
- 需要導(dǎo)入StoreKit.framework,#import <StoreKit/StoreKit.h>
- 實例化一個SKStoreProductViewController類
- 設(shè)置它的delegate
- 把sotre product視圖控制器顯示給消費者
注意: SKStoreProductViewController只能以模態(tài)的方式彈出
- 示例代碼
//pId 是APP在AppleStore上的id
- (void)presentProductInfoWithId:(NSString *)pId
{
SKStoreProductViewController *spCtrl = [[SKStoreProductViewController alloc] init];
//有一個代理方法胁黑,在完成/取消購買操作的時候調(diào)用涩盾,可以用于返回之前的頁面
spCtrl.delegate = self;
[spCtrl loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:pId}
completionBlock:^(BOOL result, NSError *error) {
if (result)
{
} else
{
NSLog(@"%@", error);
}
}];
//In most cases, you should load the product information and then present the view controller. However, if you load new product information while the view controller is presented, the contents of the view controller are replaced after the new product data is loaded. -- 摘自官方文檔
//由于loadProductWithParameters是同步的,有時候需要等很久才會block回調(diào)捕捂,所以直接彈出控制器功咒,等到信息獲取到之后,會自動刷新彈出的控制器界面內(nèi)容
[self presentViewController:spCtrl
animated:YES
completion:nil];
}
#pragma mark - SKStoreProductViewControllerDelegate
//在代理方法中绞蹦,將視圖dismiss
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
[viewController dismissViewControllerAnimated:YES completion:nil];
}
應(yīng)用內(nèi)評分
在10.3系統(tǒng),蘋果終于支持在APP內(nèi)直接評分了榜旦,而不是跳轉(zhuǎn)到商店去幽七,這樣讓很多APP的用戶都失去了想去評分的想法(吐槽的可能例外)
- 我們可以直接使用SKStoreReviewController這個類,調(diào)用起來很簡單 [SKStoreReviewController requestReview]
注意:不是正式的release版本溅呢,評分彈出框無法進行提交澡屡;一年只允許彈出3次
- 示例代碼
//__IPHONE_10_3
- (void)rateAction
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100300
[SKStoreReviewController requestReview];
#else
{
NSString *appId = @"yourAppId";
NSString *urlStr = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%@?action=write-review", appId];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
}
#endif
}