Reputation: 159
We added Push Notifications to our App but we need help with sending the Device Token to our database. As of right now we have our database set up so all we have to do is get our Device Token from the NSLog and put it at the end of the database's URL:http://www8.XXXXXXX.net/XXXXX_push/register.cfm?token=TOKEN_HERE If we use Safari we can just type that in the URL bar with the real Token at the end then hit enter and the database receives Token. We Fell that we need to put code in the App under:
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
But we just don't know what code to use...As we are really new to this.
Could someone please let us know what code to use to send the NSURL that we have made?
P.S. here is what we have so far:
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *str = [NSString
stringWithFormat:@"Device Token=%@",deviceToken];
NSLog(str);
NSString *fullURL = [NSString stringWithFormat:@"http://www8.xxxxxxxxx.net/xxxxx_push/register.cfm?token=%@",str];
NSURL *tokenURL = [NSURL URLWithString:fullURL];
}
Upvotes: 1
Views: 2261
Reputation: 19
Yes. first you need to clean-up the deviceToken received from APNS. You need to remove ..
you can use NSString message stringByReplacingOccurrencesOfString to remove.
Next step will be to construct the URL which you can load and connect with server along with device token. You can use NSURlConnection to load any URL. This URL will be configured with device token and will be used to connect with the server.
Upvotes: 0
Reputation: 303
didRegisterForRemoteNotificationsWithDeviceToken is the right spot for waht you are doing.
I use this code, borrowed from urbanairship.com, to clean up the deviceToken before sending it back via a NSURLConnection PUT to the urbanairship servers.
NSString *deviceToken = [[_deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""];
deviceToken = [deviceToken stringByReplacingOccurrencesOfString: @">" withString: @""] ;
deviceToken = [deviceToken stringByReplacingOccurrencesOfString: @" " withString: @""];
Upvotes: 5