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

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

大家都知道,評論評分是決定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是唯一的,
appleIDhttps://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