iphone - Check if an app is installed

别说谁变了你拦得住时间么 提交于 2019-11-29 18:15:07

This is not possible on non-jailbroken iOS devices—the app sandbox prevents it. You can test for some individual applications, if you know the URL schemes they implement (e.g. tel:// for the Phone app), by calling [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"someScheme://blah"]], but if an app doesn’t respond to any URL schemes then you’re not going to be able to determine whether it’s present on the device.

On a jailbroken device you can check against the apps binary:

-(BOOL)isWrightsCSInstalled
{
    return [[NSFileManager defaultManager] fileExistsAtPath:@"/Applications/WrightsCS.app/WrightsCS"];
}

Or, if you know the app has a custom URL Schema you can check if the URL can be opened:

- (BOOL) isTwitterInstalled 
{
    if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"twitter://"]] )
        return YES;
    else
        return NO;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!