0

I am new to iOS and swift with some experience in android. I am using the GCDWebUploader. Its working fine.

The server suspends when the app is in background. I am aware of the constraints in iOS Background Execution. I dont want to change that behaviour.

But I found in GCDWebServer documentation that we can disable this suspension. Check here https://github.com/swisspol/GCDWebServer#gcdwebserver--background-mode-for-ios-apps. Specifically this part

If the app goes in the background while no HTTP connections are opened, GCDWebServer will immediately suspend itself and stop accepting new connections as if you had called -stop (this behavior can be disabled with the ****GCDWebServerOption_AutomaticallySuspendInBackground**** option).

How do you set this option. I tried

GCDWebServerOption_AutomaticallySuspendInBackground = "NO"

And I get the obvious error:

Cannot assign to value: 'GCDWebServerOption_AutomaticallySuspendInBackground' is a 'let' constant

4

1 回答 1

3

您应该使用NSDictionaryGCDWebServer 实例中的以下方法传递配置选项:

- (BOOL)startWithOptions:(NSDictionary*)options error:(NSError**)error;

编辑:一个在 Objective-C 中使用即时字典的实际示例:

NSError*myError = nil;
self.webServer = [[GCDWebServer alloc] init];
BOOL success = [self.webServer startWithOptions:@{
               GCDWebServerOption_AutomaticallySuspendInBackground : @(NO)
               } error:&myError];

SWIFT代码

var myError: NSError?
let webServer = GCDWebServer()
webServer.startWithOptions([GCDWebServerOption_AutomaticallySuspendInBackground : false], error: myError)

一个小提示:如果你想改变 GCDWebServer 的日志级别,你可以使用静态方法:

[GCDWebServer setLogLevel:4];
于 2016-06-29T13:42:39.393 回答