【问题标题】:iOS Private API: wake app from backgroundiOS Private API:从后台唤醒应用程序
【发布时间】:2017-02-15 16:00:15
【问题描述】:

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

没用

【问题讨论】:

    标签: ios objective-c iphone-privateapi


    【解决方案1】:

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

    【讨论】:

    • LSApplicationWorkspace 类
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-16
    • 1970-01-01
    相关资源
    最近更新 更多