美文网首页
判断有无安装某个app,并跳转app或者appStore单页

判断有无安装某个app,并跳转app或者appStore单页

作者: zxh123456 | 来源:发表于2019-11-08 11:14 被阅读0次

    需求:
    某界面推广app下载,如果手机安装了app,直接Scheme跳转跳转app。如果没有安装,modal出appStore单页。

    分析:
    1.Scheme跳转--简单

    2.SKStoreProductViewController展示appStore单页,也简单

    3.如何知道目标app有没安装?

    方法一:私有api,不能上架。
    方法二:info.plist中的LSApplicationQueriesSchemes数组,添加上目标app的Scheme,就可以通过[[UIApplication sharedApplication] canOpenURL:url]判断了

    image.png image.png
    image.png
    #import <StoreKit/StoreKit.h>
    //实现 SKStoreProductViewControllerDelegate
    ...
    //调用 [self openAppWithIdentifier:@"1435852455"];
    
    - (void)openAppWithIdentifier:(NSString*)appId {
        SKStoreProductViewController *storeProductVC = [[SKStoreProductViewController alloc] init];
        storeProductVC.delegate=self;
        //必须先弹出,再加载数据
        [self presentViewController:storeProductVC animated:YES completion:nil];
        NSDictionary*dict = [NSDictionary dictionaryWithObject:appId forKey:SKStoreProductParameterITunesItemIdentifier];
        //加载数据
        [storeProductVC loadProductWithParameters:dict completionBlock:^(BOOL result,NSError *error) {
            if(result) {
                //改变大小
                storeProductVC.view.frame = CGRectMake(0, 200, self.view.frame.size.width, self.view.frame.size.height - 260);
                storeProductVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
            }
        }];
    
    }
    
    #pragma mark -协议方法
    - (void)productViewControllerDidFinish:(SKStoreProductViewController*)viewController{
        NSLog(@"关闭界面");
        [viewController dismissViewControllerAnimated:YES completion:nil];
    }
    
    

    相关文章

      网友评论

          本文标题:判断有无安装某个app,并跳转app或者appStore单页

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