首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在iOS中使用解析推送通知

在iOS中使用解析推送通知
EN

Stack Overflow用户
提问于 2015-03-23 21:53:13
回答 1查看 55关注 0票数 0

我正在尝试为每个应用程序用户设置一个独特的频道。

代码语言:javascript
复制
- (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];
}

通道名称的日志为:

代码语言:javascript
复制
CANAL=a35EFF93B-6CD0-4D09-9AE2... (hidden here rest of id)

但是我得到了一个错误:

代码语言:javascript
复制
[Error]: Channel name must start with a letter

如您所见,通道名称以字母开头。我在这里做错了什么?

编辑过的

代码语言:javascript
复制
- (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];
}
EN

回答 1

Stack Overflow用户

发布于 2015-03-23 22:53:47

替换此行

currentInstallation设置setDeviceTokenFromData:设备;

有了这个

代码语言:javascript
复制
NSString *tokenString = [NSString stringWithUTF8String:[deviceToken bytes]];

NSString* neweviceToken = [[[[tokenString description]
                     stringByReplacingOccurrencesOfString: @"<" withString: @""] 
                    stringByReplacingOccurrencesOfString: @">" withString: @""] 
                   stringByReplacingOccurrencesOfString: @" " withString: @""];

[currentInstallation setDeviceTokenFromData:newDeviceToken];

还有奔跑。

可能会对你有帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29212035

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档