本机有app打开app 没有app跳到appStore

2016-10-25  本文已影响0人  啷里个啷里个啷个里个啷

//创建一个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:^{

}];

}

上一篇下一篇

猜你喜欢

热点阅读