我正在尝试为每个应用程序用户设置一个独特的频道。
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Store the deviceToken in the current Installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
UIDevice *device = [UIDevice currentDevice];
NSString *currentDeviceId = [[device identifierForVendor]UUIDString];
NSLog(@"DEVICE=%@",currentDeviceId);
NSMutableString *canal = [[NSMutableString alloc] initWithString:@"a" ];
[canal appendString:currentDeviceId];
NSLog(@"CANAL=%@",canal);
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation addUniqueObject:canal forKey:@"channels"];
[currentInstallation saveInBackground];
}通道名称的日志为:
CANAL=a35EFF93B-6CD0-4D09-9AE2... (hidden here rest of id)但是我得到了一个错误:
[Error]: Channel name must start with a letter如您所见,通道名称以字母开头。我在这里做错了什么?
编辑过的
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Store the deviceToken in the current Installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
UIDevice *device = [UIDevice currentDevice];
NSString *currentDeviceId = [[device identifierForVendor]UUIDString];
NSLog(@"DEVICE=%@",currentDeviceId);
NSMutableString *canal = [[NSMutableString alloc] initWithString:@"a" ];
[canal appendString:currentDeviceId];
NSLog(@"CANAL=%@",canal);
if (currentInstallation.channels == nil)
{
currentInstallation.channels = [[NSArray alloc] init];
}
[currentInstallation addUniqueObject:canal forKey:@"channels"];
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation saveInBackground];
}发布于 2015-03-23 22:53:47
替换此行
currentInstallation设置setDeviceTokenFromData:设备;
有了这个
NSString *tokenString = [NSString stringWithUTF8String:[deviceToken bytes]];
NSString* neweviceToken = [[[[tokenString description]
stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
[currentInstallation setDeviceTokenFromData:newDeviceToken];还有奔跑。
可能会对你有帮助。
https://stackoverflow.com/questions/29212035
复制相似问题