1. 程式人生 > >iOS開發用如何用類"SKStoreProductViewController"跳轉AppStore點贊評分?

iOS開發用如何用類"SKStoreProductViewController"跳轉AppStore點贊評分?

自己 item ios nss head 下載安裝 war 不同的 提示

大家都知道,評論評分是決定appappstore中排名的重要因素,但是大部分用戶下載安裝APP後卻不會去點評,所以添加提示用戶去點評的功能是很必要的。

目前,AppStore點贊評分有兩種方法,一種是跳出應用,跳轉到AppStore;進行評分.另一種是在應用內,內置AppStore進行評分.

序號方法備註
in:在應用,內置AppStore進行評分 利用系統類:<br />SKStoreProductViewController
out:跳出應用,跳轉到AppStore,進行評分 利用方法:<br />[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]

方法一:在應用內,內置AppStore進行評分

1、添加依賴 #import<StoreKit/StoreKit.h>
2、添加代理 <SKStoreProductViewControllerDelegate>
3、添加代碼:調用跳轉方法 [self thumbsUpWithAppStore];

//贊一個
- (void)thumbsUpWithAppStore
        {
            SKStoreProductViewController *storeProductViewContorller = [[SKStoreProductViewController alloc] init];
            
//設置代理請求為當前控制器本身 storeProductViewContorller.delegate = self; //加載一個新的視圖展示 [storeProductViewContorller loadProductWithParameters: //appId唯一的 @{SKStoreProductParameterITunesItemIdentifier : @"587767923"} completionBlock:^(BOOL result, NSError *error) {
//block回調 if(error){ NSLog(@"error %@ with userInfo %@",error,[error userInfo]); }else{ //模態彈出appstore [self presentViewController:storeProductViewContorller animated:YES completion:^{ } ]; } }]; }

遵循代理SKStoreProductViewControllerDelegate:取消按鈕監聽

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController{
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}

註意:appId是唯一的,
appleID在 https://itunesconnect.apple.com 中創建應用即可在應用界面獲得。下文有截圖。
即不同的app不同的appid,請用自己工程的appid
以上代碼用雲遊平遙appid:587767923;

方法二:跳出應用,跳轉到AppStore,進行評分

App Store上評論的鏈接地址有種,分為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為自己appappid
代碼:
-(void)goToAppStore
{    
如果是7.0以前的系統
    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以後的系統

NSString *str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id547203890"];  

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];  
}

**註意: **
這個appIDitunes connect裏面你提交app 時候自動生成的,是apple的唯一的ID。方法二中:將appid鏈接中將xxxxxxx替換為54720389

技術分享圖片

iOS開發用如何用類"SKStoreProductViewController"跳轉AppStore點贊評分?