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



我需要有一个演示应用程序,它将在计时器事件时从后台唤醒自己。使用私有 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);

没用

最后,

我找到了使用私有 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

最新更新