2

I am using GCDWebServer cocoapod and trying to start static code :

GCDWebServer* webServer = [[GCDWebServer alloc] init];
[webServer addGETHandlerForBasePath:@"/" directoryPath:NSHomeDirectory() indexFilename:nil cacheAge:3600 allowRangeRequests:YES];
[webServer runWithPort:8080];

GCDWebServer not able to find runWithPort method.

enter image description here

ChenYilong
  • 8,543
  • 9
  • 56
  • 84
  • Try to follow the example listed in the official repository: https://github.com/swisspol/GCDWebServer – gabriel May 05 '15 at 11:00
  • are you sure it is `runWithPort:` method coz I have [Class Reference](http://cocoadocs.org/docsets/GCDWebServer/2.4/Classes/GCDWebServer.html) open but I am unable to find the method. – Vivek Molkar May 05 '15 at 12:01
  • Yup the same example code is listed here - https://github.com/swisspol/GCDWebServer#serving-a-static-website – Abhishek Nalwaya May 05 '15 at 17:12

3 Answers3

0

You are trying to use the old method signature that the example is also incorrectly using and needs updating. The new one is:

- (BOOL)runWithPort:(NSUInteger)port bonjourName:(NSString*)name;

Pass nil for the bonjourName so it behaves like the old method signature.

dbainbridge
  • 1,190
  • 11
  • 18
0

runWithPort:: does not exists. It's startWithPort::.

The documentation uses both, but only startWithPort works.

Johan Nordberg
  • 3,621
  • 4
  • 33
  • 58
0

You will need to use startWithPort method and consider passing full path of your directory to directoryPath, please have a look at my code example below:

private func loadDefaultIndexFile() {
    let mainBundle = NSBundle.mainBundle()
    let folderPath = mainBundle.pathForResource("www", ofType: nil)
    print("HTML base folder Path: \(folderPath)")
    self.gcdWebServer.addGETHandlerForBasePath("/", directoryPath: folderPath, indexFilename: "index.html", cacheAge: 0, allowRangeRequests: true)
    self.gcdWebServer.startWithPort(8080, bonjourName: nil)
    self.webView.loadRequest(NSURLRequest(URL: self.gcdWebServer.serverURL))
}

Hope it helps

Jack Vo
  • 319
  • 2
  • 14