我只为自己制作一个 iOS 应用程序。当应用程序在后台时,我需要每 30 分钟执行一次某些代码。
因为我只是这个应用程序的用户,所以不需要担心击球率和苹果审查过程。我可以使用任何/所有背景模式 VOIP、音乐等。
是否可以每 30 分钟在后台运行该代码?请指导我方向。
我已经经历了这么多链接,即使在那之后我还没有找到适当的解决方案来获取经度和经度.
我尝试从一些链接和论坛,但它只工作3分钟,然后应用程序根本没有更新用户位置.
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
//create new uiBackgroundTask
__block UIBackgroundTaskIdentifier bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
//and create new timer with async …Run Code Online (Sandbox Code Playgroud)