iphone SprintBoard部分私有API总结(不支持iOS8)

 本文介绍iOS SrpintBoard框架的部分私有API,具体包括:ios

  • 获取ios上当前正在运行的全部App的bundle id(无论当前程序是在前台仍是后台均可以)
  • 获取ios上当前前台运行的App的bundle id(无论当前程序是在前台仍是后台均可以)
  • 根据ios app的bundle id获得其App名称、图标(无论当前程序是在前台仍是后台均可以)
  • 直接经过App 的bundle id来运行该App,无需使用url scheme(仅限当前程序在前台时,假如程序在后台能随便运行其余App,那就无敌了@_@)

(1)初始化app

    void * uikit = dlopen("/System/Library/Framework/UIKit.framework/UIKit", RTLD_LAZY);
    int (*SBSSpringBoardServerPort)() =
    dlsym(uikit, "SBSSpringBoardServerPort");
    p = (mach_port_t *)SBSSpringBoardServerPort();
    dlclose(uikit);
    sbserv = dlopen(SBSERVPATH, RTLD_LAZY);

(2)获取iphone上全部正在运行的app的bundle id列表框架

 

NSArray* (*SBSCopyApplicationDisplayIdentifiers)(mach_port_t* port, BOOL runningApps,BOOL debuggablet) =

                    dlsym(sbserv, "SBSCopyApplicationDisplayIdentifiers");

NSArray *currentRunningAppBundleIdArray= SBSCopyApplicationDisplayIdentifiers(p,NO,YES);

 

(3)获得iphone 前台运行的app的bundle idiphone

void* (*SBFrontmostApplicationDisplayIdentifier)(mach_port_t* port,char * result) = dlsym(sbserv, "SBFrontmostApplicationDisplayIdentifier");
char topapp[256];
SBFrontmostApplicationDisplayIdentifier(p,topapp); currentTopAppBundleId
=[NSStringstringWithFormat:@"%s",topapp];

(4)根据iphone app的bundle id获得其app名称ide

 NSString * (*SBSCopyLocalizedApplicationNameForDisplayIdentifier)(NSString* ) =   dlsym(sbserv, "SBSCopyLocalizedApplicationNameForDisplayIdentifier");

NSString *strAppName = SBSCopyLocalizedApplicationNameForDisplayIdentifier(strBundleId);

 (5)根据iphone app 的bundle id获得其图标ui

 NSData* (*SBSCopyIconImagePNGDataForDisplayIdentifier)(NSString * bundleid) =
    dlsym(sbserv, "SBSCopyIconImagePNGDataForDisplayIdentifier");
    UIImage *icon = nil;
    NSData *iconData = SBSCopyIconImagePNGDataForDisplayIdentifier(bundleid);
    if (iconData != nil) {
        icon = [UIImage imageWithData:iconData];   
    }
    return icon;

(6)直接经过app 的bundle id来运行该appurl

 在ios中,一个app调起另外一个app的方式一般是用url scheme,可是用这个 私有app,能够在不须要url scheme的状况下运行任何appspa

-(void)openAppByBundleId:(NSString*)bundleId
{
    void* sbServices = dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_LAZY);
    int (*SBSLaunchApplicationWithIdentifier)(CFStringRef identifier, Boolean suspended) = dlsym(sbServices, "SBSLaunchApplicationWithIdentifier");
    const char *strBundleId = [bundleId cStringUsingEncoding:NSUTF8StringEncoding];
    int result = SBSLaunchApplicationWithIdentifier((__bridge CFStringRef)bundleId, NO);
    dlclose(sbServices);
}
相关文章
相关标签/搜索