1. 程式人生 > >ios應用內跳轉到appstore裡評分

ios應用內跳轉到appstore裡評分

在ios6.0前跳轉到appstore評分一般是直接跳轉到appstore評分
NSString *evaluateString = [NSString stringWithFormat:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=587767923"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:evaluateString]];

在ios6.0,APPle增加了一個心得功能,當用戶需要給APP評分時候,不再跳轉到appstore了,可以在應用內實現開啟appstore,蘋果提供了一個框架StoreKit.framework,實現步驟如下:
  1:匯入StoreKit.framework,在需要跳轉的控制器裡面新增標頭檔案#import
  2:實現代理SKStoreProductViewControllerDelegate
  3:- (void)evaluate{
   
    //初始化控制器
    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:^{
               
            }
             ];
        }
    }];
}

//取消按鈕監聽
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController{
    [self dismissViewControllerAnimated:YES completion:^{
       
    }];
}
就很輕鬆實現了應用內建appstore評分功能。