[英]Push notifications in iOS with Parse
我正在嘗試為每個應用程序用戶設置一個唯一的渠道。
- (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];
}
替換此行
[currentInstallation setDeviceTokenFromData:deviceToken];
有了這個
NSString *tokenString = [NSString stringWithUTF8String:[deviceToken bytes]];
NSString* neweviceToken = [[[[tokenString description]
stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
[currentInstallation setDeviceTokenFromData:newDeviceToken];
和運行。
可以幫助您。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.