2017-02-14 183 views
-1

我需要有一个演示应用程序,它将在计时器事件中从后台唤醒自己。使用私人API可以不越狱?尝试这种代码:iOS私有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); 

没有工作

回答

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 
+0

这是上述代码中的私人API? – Hisenberg

+0

LSApplicationWorkspace类 – Rost

+0

它正在使用iOS 10吗? – Hisenberg

相关问题