私は次のような形式でサーバーに送信する必要があるアプリに取り組んでいます:この形式でsを保存してサーバーに送信するにはどうすればよいdeviceToken
ですか?uuid
JSON
"regid":"x1y2z3","uuid":"1a2b3c"
NSString
NSData
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];