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

需求:
某界面推广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];
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。