Skip to content

Instantly share code, notes, and snippets.

@yasuoza
Created March 27, 2015 05:21
Show Gist options
  • Save yasuoza/65ade65c942f96fe0150 to your computer and use it in GitHub Desktop.
Save yasuoza/65ade65c942f96fe0150 to your computer and use it in GitHub Desktop.
Install configuration profile through iOS application with CocoaHTTPServer
/*
* Be sure not to close local server at `applicationDidEnterBackground:`.
* This causes file not found error in Safari.
*/
class LocalHTTPConnection: HTTPConnection {
override func httpResponseForMethod(method: String!, URI path: String!) -> NSObject! {
if path == LocalWebViewRouter.Profile.URL.path {
return LocalProfileReponse(filePath: self.filePathForURI(path), forConnection: self)
}
return super.httpResponseForMethod(method, URI: path)
}
}
class LocalProfileReponse: HTTPFileResponse {
override func httpHeaders() -> [NSObject : AnyObject]! {
return ["Content-Type": "application/x-apple-aspen-config"]
}
}
self.server.setConnectionClass(LocalHTTPConnection.self)
self.server.start()
UIApplication.sharedApplication.openURL(url: LocalWebViewRouter.Profile.URL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment