iOS開發用如何用類";SKStoreProductViewController";跳轉AppStore點贊評分?
阿新 • • 發佈:2020-10-15
大家都知道,評論
和評分
是決定app
在appstore
中排名的重要因素,但是大部分使用者下載安裝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 為自己app 的appid |
程式碼:
-(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]]; }
**注意: **
這個appID
是itunes connect
裡面你提交app
時候自動生成的,是apple
的唯一的ID
。方法二中:將appid
連結中將xxxxxxx
替換為54720389
。