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