繁体   English   中英

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

[英]iOS Private API: wake app from background

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM