Contents |
URL
https://api.geoloqi.com/1/account/set_apn_token
Description
Stores the push token in the API. This is called after the device registers for push notifications.
Supported Request Methods
POST
Parameters
- device_id RequiredThe Apple device ID for this device.
- token RequiredThe Apple Push Notification token.
Getting the information in iOS
Getting the push token
This method will be called by the OS after the user approves push access to your app. This sample code will get the push token and send the necessary information to the Geoloqi API.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken { NSString *deviceToken = [[[[_deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""] stringByReplacingOccurrencesOfString: @">" withString: @""] stringByReplacingOccurrencesOfString: @" " withString: @""]; UIDevice *d = [UIDevice currentDevice]; // Send the request to Geoloqi NSURL *url = [NSURL URLWithString:@"https://api.geoloqi.com/1/account/set_apn_token"]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; [request setHTTPMethod:@"POST"]; // Authenticate to the server [request addValue:[NSString stringWithFormat:@"Basic %@", [GeoloqiAppDelegate base64forData:[[NSString stringWithFormat:@"%@:%@", LQClientID, LQClientSecret] dataUsingEncoding: NSUTF8StringEncoding]]] forHTTPHeaderField:@"Authorization"]; [request setHTTPBody:[[NSString stringWithFormat:@"token=%@&device_id=%@", deviceToken, d.uniqueIdentifier] dataUsingEncoding:NSUTF8StringEncoding]]; [[NSURLConnection connectionWithRequest:request delegate:self] start]; [request release]; }
Response
Success
If the device token was accepted successfully, you will get an "ok" response. Otherwise you will get a standard error response.
{ "response":"ok" }