参考文章:https://www.jianshu.com/p/2bab0ef93f7d
1.开启支持后台模式:将GCDWebServer.m中的GCDWebServerOption_AutomaticallySuspendInBackground设置为NO;
2.APPDelegate中
- (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. __weak typeof(self) weakSelf = self; self.backgroundTask = [application beginBackgroundTaskWithExpirationHandler:^{ [application endBackgroundTask:weakSelf.backgroundTask]; weakSelf.backgroundTask = UIBackgroundTaskInvalid; }]; }