I am working on an app in which I have to send deviceToken
and uuid
to server in JSON
format like: "regid":"x1y2z3","uuid":"1a2b3c"
how can I store the NSString
s into NSData
in this format and send it to server?
regid
string is like x1y2z3
and uuid
string is like 1a2b3c
.
my code :
PushNotification* pushHandler = [self.viewController getCommandInstance:@"PushNotification"];
[pushHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
NSString *deviceT = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
NSString *tkStr = [[NSString alloc]initWithData:deviceToken encoding:NSUTF8StringEncoding];
tkStr = [deviceT stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"Device Token = %@",tkStr);
//UUID
CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
NSString *uuidStr = ( NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid);
CFRelease(uuid);
NSString *finalUIDstr = [uuidStr stringByReplacingOccurrencesOfString:@"-" withString:@""];
NSLog(@"UUID = %@",finalUIDstr);
NSArray *keysArray = [NSArray arrayWithObjects:@"regid", @"uuid", nil];
NSArray *objectArray = [NSArray arrayWithObjects:tkStr,finalUIDstr, nil];
//Dictionary
NSDictionary *jsonDict = [NSDictionary dictionaryWithObjects:objectArray forKeys:keysArray];