iOS私有API:从后台唤醒应用程序

时间:2017-02-14 13:58:22

标签: ios objective-c iphone-privateapi

我需要一个演示应用程序,它将从计时器事件的后台唤醒。是否可以通过使用私有API进行越狱?试过这段代码:

void* sbServices = dlopen(SBSERVPATH, RTLD_LAZY);
int (*SBSLaunchApplicationWithIdentifier)(CFStringRef identifier, Boolean suspended) = dlsym(sbServices, "SBSLaunchApplicationWithIdentifier");
int result;
result = SBSLaunchApplicationWithIdentifier(CFSTR("com.my.app"), false);
dlclose(sbServices);

没有工作

1 个答案:

答案 0 :(得分:0)

最后我找到了使用私有api的解决方案。以下是每10秒启动自定义应用的示例代码

@interface PrivateApi_LSApplicationWorkspace

- (bool)openApplicationWithBundleID:(id)arg1;

@end

@implementation ViewController {
    PrivateApi_LSApplicationWorkspace* _workspace;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _workspace = [NSClassFromString(@"LSApplicationWorkspace") new];

    NSTimer *timer = [NSTimer timerWithTimeInterval:10.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
        [self openAppWithBundleIdentifier:@"com.app.my"];
    }];
    [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];

}

- (BOOL)openAppWithBundleIdentifier:(NSString *)bundleIdentifier {
    return (BOOL)[_workspace openApplicationWithBundleID:bundleIdentifier];
}

@end