本機有app打開app 沒有app跳到appStore

//創建一個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:^{

}];

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容