应用内打开App Store评分

430 阅读1分钟
  1. 导入StoreKit.framework、包含头文件 #import <StoreKit/StoreKit.h>
  2. 遵循协议 <SKStoreProductViewControllerDelegate>
  3. 在该类加入如下代码

\

//showAppStore

- ( void )showStoreProductInApp:( NSString *)appID{


Class isAllow = NSClassFromString ( @"SKStoreProductViewController" );
if (isAllow != nil ) {


SKStoreProductViewController *storeProductVC = [[ SKStoreProductViewController alloc ] init ];
storeProductVC. delegate = self ;
[storeProductVC loadProductWithParameters : @{

SKStoreProductParameterITunesItemIdentifier : appID } completionBlock :^( BOOL result, NSError *error) {


if (result) {


[ self presentViewController :storeProductVC animated : YES completion : nil ];
//[self removeNotice];
} else {


NSLog ( @"error:%@" ,error);
}
}];
} else {


// 低于 iOS6 的系统版本没有这个类 , 不支持这个功能
NSString *string = [ NSString stringWithFormat : @"itms-apps://itunes.apple.com/xxxxxxx/app/id%@?mt=8" ,appID];
[[ UIApplication sharedApplication ] openURL :[ NSURL URLWithString :string]];
}
}


// 监听取消按钮
#pragma mark - SKStoreProductViewControllerDelegate
- ( void )productViewControllerDidFinish:( SKStoreProductViewController *)viewController {


[viewController dismissViewControllerAnimated : YES completion :^{


}];

}

\

//调用方法

[ self showS toreProductInApp: @"443795458" ];