[英]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.