iOS開發(fā)利用"SKStoreProductViewController"跳轉(zhuǎn)AppStore點(diǎn)贊評(píng)
大家都知道,評(píng)論和評(píng)分是決定app在appstore中排名的重要因素,但是大部分用戶下載安裝APP后卻不會(huì)去點(diǎn)評(píng),所以添加提示用戶去點(diǎn)評(píng)的功能是很必要的。
目前,AppStore點(diǎn)贊評(píng)分有兩種方法,一種是跳出應(yīng)用,跳轉(zhuǎn)到AppStore;進(jìn)行評(píng)分.另一種是在應(yīng)用里內(nèi)置AppStore進(jìn)行評(píng)分.
| 序號(hào) | 方法 | 備注 |
|---|---|---|
| ① |
in:在應(yīng)用里內(nèi)置AppStore進(jìn)行評(píng)分 |
利用系統(tǒng)類:SKStoreProductViewController
|
| ② |
out:跳出應(yīng)用,跳轉(zhuǎn)到AppStore,進(jìn)行評(píng)分 |
利用方法:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]
|
方法一:在應(yīng)用內(nèi),內(nèi)置AppStore進(jìn)行評(píng)分
1、添加依賴 #import<StoreKit/StoreKit.h>
2、添加代理 <SKStoreProductViewControllerDelegate>
3、添加代碼:調(diào)用跳轉(zhuǎn)方法 [self thumbsUpWithAppStore];
- (void)thumbsUpWithAppStore {
SKStoreProductViewController *storeProductViewContorller = [[SKStoreProductViewController alloc] init];
//設(shè)置代理請(qǐng)求為當(dāng)前控制器本身
storeProductViewContorller.delegate = self; //加載一個(gè)新的視圖展示
[storeProductViewContorller loadProductWithParameters: //appId唯一的
[SKStoreProductParameterITunesItemIdentifier : @"自己平臺(tái)的appid"} completionBlock:^(BOOL result, NSError *error) { //block回調(diào)
if(error){
NSLog(@"error %@ with userInfo %@",error,[error userInfo]);
}else{ //模態(tài)彈出appstore
[self presentViewController:storeProductViewContorller animated:YES completion:^{
}];
}
}];
}
遵循代理SKStoreProductViewControllerDelegate:取消按鈕監(jiān)聽
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController{
[self dismissViewControllerAnimated:YES completion:^{
}];
}
注意:appId是唯一的,
appleID在 https://itunesconnect.apple.com 中創(chuàng)建應(yīng)用即可在應(yīng)用界面獲得
即不同的app不同的appid,請(qǐng)用自己工程的appid。
**注意: **
這個(gè)appID 是itunes connect里面你提交app 時(shí)候自動(dòng)生成的,是apple的唯一的ID。方法二中:將appid鏈接中將xxxxxxx替換為自己應(yīng)用appid。
方法二:跳出應(yīng)用,跳轉(zhuǎn)到AppStore,進(jìn)行評(píng)分
App Store上評(píng)論的鏈接地址有二種,分為iOS7前后鏈接:
| 分類 | 鏈接 | 說明 |
|---|---|---|
iOS7之前鏈接 |
itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id = xxxxxxxx |
其中xxxxxxxx為自己app的aped
|
iOS7之后鏈接 |
itms-apps://itunes.apple.com/app/idxxxxxxxxx |
其中xxxxxxxx為自己app的appid
|
代碼:
-(void)goToAppStore
{
如果是7.0以前的系統(tǒng)
NSString *str = [NSString stringWithFormat: @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%d",547203890];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
如果是7.0以后的系統(tǒng)
NSString *str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id547203890"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}