//創建一個url
NSURL*url = [NSURLURLWithString:app.scheme];
if([[UIApplicationsharedApplication]canOpenURL:url]) {
//裝了app打開app
[[UIApplicationsharedApplication]openURL:url];
}else{
NSString*appStoreString =nil;
//沒有裝app跳到appStore
if([app.appStoreUrl.lowercaseStringhasPrefix:@"http://"] || [app.appStoreUrl.lowercaseStringhasPrefix:@"https://"]) {
NSArray*array = [app.appStoreUrlcomponentsSeparatedByString:@"://"];
if(array.count==2) {
appStoreString = [NSStringstringWithFormat:@"itms://%@",array[1]];
}
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:appStoreString]];
}elseif([app.appStoreUrl.lowercaseStringhasPrefix:@"itms://"] || [app.appStoreUrl.lowercaseStringhasPrefix:@"itms-apps://"]){
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:app.appStoreUrl]];
}else{
UIAlertView*alertView = [[[UIAlertViewalloc]initWithTitle:@"提示"message:@"應用鏈接不正確"delegate:nilcancelButtonTitle:@"確定"otherButtonTitles:nil]autorelease];
[alertViewshow];
}
}
跳轉appstore也可以用下面的代碼
#import <StoreKit/StoreKit.h>
//初始化控制器
SKStoreProductViewController*storeProductViewContorller = [[[SKStoreProductViewControlleralloc]init]autorelease];
//設置代理請求為當前控制器本身
storeProductViewContorller.delegate=self;
//加載一個新的視圖展示
[storeProductViewContorllerloadProductWithParameters:
//appId唯一的
@{SKStoreProductParameterITunesItemIdentifier:@"1019225065"}completionBlock:^(BOOLresult,NSError*error) {
//block回調
if(error){
NSLog(@"error %@ with userInfo %@",error,[erroruserInfo]);
}else{
//模態彈出appstore
[selfpresentViewController:storeProductViewContorlleranimated:YEScompletion:^{
}];
}
}];
#pragma mark - SKStoreProductViewControllerDelegate
//取消按鈕監聽
- (void)productViewControllerDidFinish:(SKStoreProductViewController*)viewController{
[selfdismissViewControllerAnimated:YEScompletion:^{
}];
}