美文网首页
iOS 获取手机安装的应用列表

iOS 获取手机安装的应用列表

作者: 浅夏_流年 | 来源:发表于2018-12-25 11:06 被阅读0次

    在iOS 11 以前我们可以使用LSApplicationWorkspace来获取手机上已安装的应用列表

    - (void)getIphoneAllApplications {

        ClassLSApplicationWorkspace_class =objc_getClass("LSApplicationWorkspace");

        NSObject* workspace = [LSApplicationWorkspace_classperformSelector:@selector(defaultWorkspace)];

        NSArray*apps= [workspaceperformSelector:@selector(allApplications)];

        ClassLSApplicationProxy_class =objc_getClass("LSApplicationProxy");

        for(inti =0; i < apps.count; i++) {

            NSObject*temp = apps[i];

            if([tempisKindOfClass:LSApplicationProxy_class])

            {

                //应用的bundleId

                NSString*appBundleId = [tempperformSelector:NSSelectorFromString(@"applicationIdentifier")];

                //应用的名称

                NSString *appName = [temp performSelector:NSSelectorFromString(@"localizedName")];

                //应用的类型是系统的应用还是第三方的应用

                NSString * type = [temp performSelector:NSSelectorFromString(@"applicationType")];

                //应用的版本

                NSString* shortVersionString = [tempperformSelector:NSSelectorFromString(@"shortVersionString")];

                NSString* resourcesDirectoryURL = [tempperformSelector:NSSelectorFromString(@"containerURL")];

                NSLog(@"类型=%@应用的BundleId=%@ ++++应用的名称=%@版本号=%@\n%@",type,appBundleId,appName,shortVersionString,resourcesDirectoryURL);

            }

        }

    }

    iOS 11 上获取所有已安装应用接口被禁,但可以根据BundleId检查App是否存在

    - (BOOL)isInstalled:(NSString *)bundleId {

        NSBundle *container = [NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/MobileContainerManager.framework"];

        if ([container load]) {

            Class appContainer = NSClassFromString(@"MCMAppContainer");#pragmaclang diagnostic push#pragmaclang diagnostic ignored "-Wundeclared-selector"idcontainer = [appContainer performSelector:@selector(containerWithIdentifier:error:) withObject:bundleId withObject:nil];#pragmaclang diagnostic pop        NSLog(@"%@", [container performSelector:@selector(identifier)]);

            if (container) {

                return YES;

            } else {

                return NO;

            }

        }

        return NO;

    }

    相关文章

      网友评论

          本文标题:iOS 获取手机安装的应用列表

          本文链接:https://www.haomeiwen.com/subject/nwgxlqtx.html