iOS 检测手机中是否安装其他应用

 if ([[UIDevice currentDevice].systemVersion floatValue] >= 11.0) {
        NSBundle *container = [NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/MobileContainerManager.framework"];
        if ([container load]) {
            Class appContainer = NSClassFromString(@"MCMAppContainer");
            id test = [appContainer performSelector:@selector(containerWithIdentifier:error:) withObject:BundleID withObject:nil];
            NSLog(@"%@",test);
            if (test) {
                //YES;
            } else {
                //NO;
            }
        }else{
            //NO
        }
        
    } else {
        Class lsawsc = objc_getClass("LSApplicationWorkspace");
        NSObject* workspace = [lsawsc performSelector:NSSelectorFromString(@"defaultWorkspace")];
        NSArray *appList = [workspace performSelector:@selector(allApplications)];
        Class LSApplicationProxy_class = object_getClass(@"LSApplicationProxy");
        for (LSApplicationProxy_class in appList)
        {
            //这里可以查看一些信息
            NSString *bundleID = [LSApplicationProxy_class performSelector:@selector(applicationIdentifier)];
            NSString *version =  [LSApplicationProxy_class performSelector:@selector(bundleVersion)];
            NSString *shortVersionString =  [LSApplicationProxy_class performSelector:@selector(shortVersionString)];


            if ([bundleID isEqualToString:BundleID]) {
                return  YES;
            }
        }

    }


iOS10之后不能直接获取了,需要用到私有库,上store会有问题可以用到反射机制避免。 

iOS10是可以直接获取应用列表的


猜你喜欢

转载自blog.csdn.net/chengqiang0414/article/details/80953149