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

转载自:   http://www.cnblogs.com/gugupluto/p/3206772.html

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

  • 获取ios上当前正在运行的所有App的bundle id(不管当前程序是在前台还是后台都可以)
  • 获取ios上当前前台运行的App的bundle id(不管当前程序是在前台还是后台都可以)
  • 根据ios app的bundle id得到其App名称、图标(不管当前程序是在前台还是后台都可以)
  • 直接通过App 的bundle id来运行该App,无需使用url scheme(仅限当前程序在前台时,假如程序在后台能随便运行其他App,那就无敌了@_@)

(1)初始化

复制代码
    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 id

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名称

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

NSString *strAppName = SBSCopyLocalizedApplicationNameForDisplayIdentifier(strBundleId);

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

复制代码
 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来运行该app

 在ios中,一个app调起另一个app的方式通常是用url scheme,但是用这个 私有app,可以在不需要url scheme的情况下运行任何app

复制代码
-(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);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值