我正在开发一个应用程序,我必须在其中以如下格式发送deviceToken
和uuid
服务器JSON
:"regid":"x1y2z3","uuid":"1a2b3c"
如何将NSString
sNSData
以这种格式存储并将其发送到服务器?
regid
字符串就像x1y2z3
和uuid
字符串一样1a2b3c
。
我的代码:
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];