IOS_根据Bundle ID 唤醒App(获取手机里所有APP包名)


相关引用:https://github.com/wujianguo/iOSAppsInfo

@interface PrivateApi_LSApplicationWorkspace
- (bool)openApplicationWithBundleID:(id)arg1;
@end

//调用App
         
PrivateApi_LSApplicationWorkspace* workspace = [NSClassFromString(@"LSApplicationWorkspace") new];            [workspace openApplicationWithBundleID:@"com.xxx.xxx"];


//获取所有App包名

1.获取到手机里面所有的APP包名

- (void)touss
{
    Class lsawsc = objc_getClass("LSApplicationWorkspace");
    NSObject* workspace = [lsawsc performSelector:NSSelectorFromString(@"defaultWorkspace")];
    NSArray *Arr = [workspace performSelector:NSSelectorFromString(@"allInstalledApplications")];
    for (NSString * tmp in Arr)
    {
        NSString * bundleid = [self getParseBundleIdString:tmp];
        NSLog(@"%@",bundleid);
    }
}

- (NSString *)getParseBundleIdString:(NSString *)description
{
    NSString * ret = @"";
    NSString * target = [description description];

    // iOS8.0 "LSApplicationProxy: com.apple.videos",
    // iOS8.1 " com.apple.videos",
    // iOS9.0 " com.apple.PhotosViewService ///Applications/PhotosViewService.app>"

    if (target == nil)
    {
        return ret;
    }
    NSArray * arrObj = [target componentsSeparatedByString:@" "];
    switch ([arrObj count])
    {
        case 2: // [iOS7.0 ~ iOS8.1)
        case 3: // [iOS8.1 ~ iOS9.0)
        {
            ret = [arrObj lastObject];
        }
          break;
            
        case 4: // [iOS9 +)
        {
            ret = [arrObj objectAtIndex:2];
        }
          break;

        default:
            break;
    }
    return ret;
}

 2.通过包名去打开应用

    Class lsawsc = objc_getClass("LSApplicationWorkspace");
    NSObject* workspace = [lsawsc performSelector:NSSelectorFromString(@"defaultWorkspace")];
    // iOS6 没有defaultWorkspace
    if ([workspace respondsToSelector:NSSelectorFromString(@"openApplicationWithBundleID:")])
    {
        [workspace performSelector:NSSelectorFromString(@"openApplicationWithBundleID:") withObject:@"com.Calendar.jbp"];
    }

你可能感兴趣的:(IOS_私有库方法)