码迷,mamicode.com
首页 > 移动开发 > 详细

iPhone获取手机里面所有的APP(私有库)+ 通过包名打开应用

时间:2016-04-14 19:26:55      阅读:1367      评论:0      收藏:0      [点我收藏+]

标签:

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 "<LSApplicationProxy: 0x898787998> com.apple.videos",
    // iOS9.0 "<LSApplicationProxy: 0x145efbb0> com.apple.PhotosViewService <file:///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"];
    }

 

iPhone获取手机里面所有的APP(私有库)+ 通过包名打开应用

标签:

原文地址:http://www.cnblogs.com/fuunnyy/p/5392241.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!