iPhone獲取手機裏面全部的APP(私有庫)+ 經過包名打開應用

1.獲取到手機裏面全部的APP包名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.經過包名去打開應用,這裏有個坑。若是說你這個APP正在下載,經過這個去打開。是yes狀態,可是實際上這個應用根本沒有下載下來。ide

    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"];
    }
相關文章
相關標籤/搜索