美文网首页
本机有app打开app 没有app跳到appStore

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

作者: 啷里个啷里个啷个里个啷 | 来源:发表于2016-10-25 13:53 被阅读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:^{

    }];

    }

    相关文章

      网友评论

          本文标题:本机有app打开app 没有app跳到appStore

          本文链接:https://www.haomeiwen.com/subject/kouruttx.html