AGDeviceRegistration
Utility to register an iOS device with the AeroGear UnifiedPush Server.
-
An initializer method to instantiate an AGDeviceRegistration object.
Declaration
Swift
public init(serverURL: NSURL)
Parameters
serverURL
the URL of the AeroGear Push server.
Return Value
the AGDeviceRegistration object.
-
An initializer method to instantiate an AGDeviceRegistration object with default app plist config file.
Declaration
Swift
public convenience init(config: String)
Parameters
config
file name where to fetch AeroGear UnifiedPush server configuration.
Return Value
the AGDeviceRegistration object.
-
An initializer method to instantiate an AGDeviceRegistration object.
Declaration
Swift
public override init()
Return Value
the AGDeviceRegistration object.
-
Registers your mobile device to the AeroGear UnifiedPush server so it can start receiving messages. Registration information can be provided within clientInfo block or by providing a plist file containing the require registration information as below:
serverURL pushServerURL e.g http(s)//host:port/context variantID variantID e.g. 1234456-234320 variantSecret variantSecret e.g. 1234456-234320 …Declaration
Swift
public func registerWithClientInfo(clientInfo: ((config: AGClientDeviceInformation) -> Void)!, success:(() -> Void)!, failure:((NSError) -> Void)!) -> Void
Parameters
clientInfo
A block object which passes in an implementation of the AGClientDeviceInformation protocol that
success
A block object to be executed when the registration operation finishes successfully.
failure
A block object to be executed when the registration operation finishes unsuccessfully.
-
We need to cater for possible redirection NOTE: As per Apple doc, the passed req is ‘the proposed redirected request’. But we cannot return it as it is. The reason is, user-agents (and in our case NSURLconnection) ‘erroneous’ after a 302-redirection modify the request’s http method and sets it to GET if the client initially performed a POST (as we do here).
See RFC 2616 (section 10.3.3) http://www.ietf.org/rfc/rfc2616.txt and related blog: http://tewha.net/2012/05/handling-302303-redirects/ We need to 'override' that 'default' behaviour to return the original attempted NSURLRequest with the URL parameter updated to point to the new 'Location' header.
Declaration
Swift
public func URLSession(session: NSURLSession, task: NSURLSessionTask, willPerformHTTPRedirection redirectResponse: NSHTTPURLResponse, newRequest redirectReq: NSURLRequest, completionHandler: ((NSURLRequest!) -> Void))