Nsstring * STR = [devicetoken
Description];
Hfalert (STR );
// Convertthe token to a hex string and make sure it's all caps
Nsmutablestring * tokenstring = [nsmutablestring
Stringwithstring: [[devicetoken description]
Uppercasestring];
[Tokenstring replaceoccurrencesofstring: @ "<" withstring: @ "" Options: 0
Range: nsmakerange (0, tokenstring. Length)];
[Tokenstring replaceoccurrencesofstring: @ ">" withstring: @ "" Options: 0
Range: nsmakerange (0, tokenstring. Length)];
[Tokenstring replaceoccurrencesofstring: @ "" withstring: @ "" Options: 0
Range: nsmakerange (0, tokenstring. Length)];
Nslog (@ "token: % @", tokenstring );
// Create thensurl for the request
Nsstring * urlformat = @ "https://go.urbanairship.com/api/device_tokens/% ";
Nsurl * registrationurl = [nsurl
Urlwithstring: [nsstring stringwithformat:
Urlformat, tokenstring];
// Create theregistration request
Nsmutableurlrequest * registrationrequest = [nsmutableurlrequest
Alloc]
Initwithurl: registrationurl];
[Registrationrequest sethttpmethod: @ "Post"];
[Registrationrequest setvalue: @ "application/X-WWW-form-urlencoded"
Forhttpheaderfield: @ "Content-Type"];
Nsmutabledata * postbody = [nsmutabledata
Data];
[Postbody appenddata: [[nsstring
Stringwithformat: @ "username = % @",
@ "Hufeng"]
Datausingencoding: nsutf8stringencoding];
[Postbody appenddata: [[nsstring
Stringwithformat: @ "& token = % @",
Tokenstring] datausingencoding: nsutf8stringencoding];
// And fireit off
Nsurlconnection * connection = [nsurlconnection
Connectionwithrequest: registrationrequest
Delegate: Self];
[Connection start];
// Todo: passthe token to our server
Nslog (@ "we successfully registered forpush notifications ");