本机有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:^{

}];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容