앱이 백그라운드 작업을 사용하여 백그라운드로 들어간 후 최대 10 분 동안 앱을 실행할 수 있습니다. iOS 앱 프로그래밍 가이드의 Background Execution and Multitasking 섹션을 살펴보세요.
- (void)applicationDidEnterBackground:(UIApplication *)application
{
backgroundTask = [application beginBackgroundTaskWithExpirationHandler:^{
// clean up any unfinished task business, your app is going to be killed if you don't end the background task now
[application endBackgroundTask:backgroundTask];
backgroundTask = UIBackgroundTaskInvalid;
}];
// start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Monitor the head phone jack here.
// If this happens asynchronously, you don't need to dispatch this block, your app will continue to run as normal, only modifying or accessing its UI while it's in background mode is prohibited.
// End the background task if you're done. If this is never the case, your expiration handler will be called after ten minutes.
[application endBackgroundTask:backgroundTask];
backgroundTask = UIBackgroundTaskInvalid;
});
}
당신은 전송하여 사용자에게 통지 할 수있는 UILocalNotification
:
- (void)notifyUserWhilePerformingBackgroundTask
{
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = @"Headphone removed!";
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}
당신은 그것을 위해 백그라운드 작업을 사용할 수 있지만, 어떤 배경 작업이 최대 10 분 후 종료됩니다
, 당신에 대한 그 괜찮 앱? –
앱이 포 그라운드로 돌아 왔을 때 헤드폰 잭의 상태를 확인하십시오. – rmaddy
답변 해 주셔서 감사합니다. @ FabianKreiser가 작동 할 수도 있지만 "배경 작업"에 대해서는 잘 모릅니다. 헤드폰 잭을 뽑을 때마다 알림을 시작해야하며 백그라운드 작업이 가능합니까? –