準(zhǔn)備:現(xiàn)在有兩個 APP ?A 和 B熄浓,現(xiàn)在要在 B 里面檢測是否安裝了A。
方法:使用 [[UIApplication sharedApplication] openURL:url] 來判斷設(shè)備是否安裝了 APP A
一般來說点晴,在 APP 中如果自定了 URL Types ,如下圖:
NSString *urlString = @"first://";
NSURL *url = [NSURL URLWithString:urlString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
? ? ? ? [[UIApplication sharedApplication] openURL:url]
}
在 APP B中使用 [[UIApplication sharedApplication] openURL:url] 就能判斷設(shè)備是否安裝了 A 了悯周,如果您的 iOS 系統(tǒng)是 9 以下粒督,恭喜您,您應(yīng)該已經(jīng)成功了禽翼,但是不幸的是屠橄,筆者已經(jīng)升級到 Xcode 7 與 iOS 9 了,說到這里闰挡,您大概也已經(jīng)猜到了锐墙,結(jié)果肯定是失敗的,失敗的錯誤信息是:"first://myparams" - error: "This app is not allowed to query for scheme first"长酗, 這是 9 的新特性溪北,為了用戶的隱私安全,在檢測的 APP (也就是這里的 APP B )中夺脾,必須將 APP A 設(shè)置成白名單之后才能通過 canOpenURL 的檢測之拨。
注意這里需要添加 白名單 的是 ?APP B织咧,而不是被檢測的 APP A伐割,筆者就是給弄反了冬殃,折騰了好久才弄出來哗咆。?