2017-02-14 188 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

相關問題