1. 程式人生 > >判斷APP是否已安裝

判斷APP是否已安裝

repl with 沒有 sha nil option handle highlight clas

    NSString *str = [NSString stringWithFormat:@"%@://%@",[dic objectForKey:@"ios_url_scheme"],[dic objectForKey:@"app_bundle_id"]];
    NSURL *app_url = [NSURL URLWithString:str];
    BOOL hasInstalled = [[UIApplication sharedApplication] canOpenURL:app_url];
    if (hasInstalled){
        //說明此設備有安裝app,打開APP
        if (APP_Version.doubleValue <= 10) {
            [[UIApplication sharedApplication] openURL:app_url];
        }else{
            [[UIApplication sharedApplication] openURL:app_url options:@{} completionHandler:nil];
        }
    }else{
        //說明此設備沒有安裝app,跳轉APP_STORE
        NSString *link = [dic objectForKey:@"app_link_ios"];
        if (link.length != 0) {
            NSString *link_pro = [link stringByReplacingOccurrencesOfString:@"https" withString:@"itms-apps"];
            if (APP_Version.doubleValue <= 10) {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:link_pro]];
            }else{
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:link_pro] options:@{} completionHandler:nil];
            }
        }
    }

判斷APP是否已安裝