从 iOS 到 Android 的推送通知不起作用
Push notifications from iOS to Android not working
我正在尝试为我们使用 quickblox 的应用程序设置推送通知。
我已经上传了正确的 iOS 证书和 Google 密钥,
我可以:
从 iOS
发送到 iOS
从 Android
发送到 Android
从 Android
发送到 iOS
但是当我尝试从 iOS
发送到 android 时,我收到 SDK 错误消息:
"No recipients. At least one user should be subscribed for APNS (Apple
Push) (through SDK or REST API)"]
这很奇怪,因为我正在尝试向 GCM device
发送消息,但错误提示没有 APNS device
.
我该如何解决这个问题?什么可以中断从 iOS
推送到 Android
?
这就是我发送推送的方式
QBMPushMessage *pushMessage = [QBMPushMessage new];
pushMessage.alertBody = pushText;
NSMutableDictionary *additionalParams = [NSMutableDictionary new];
[additionalParams setObject:@1 forKey:@"isFromChat"];
if(dialogId){
[additionalParams setObject:dialogId forKey:@"dialogId"];
}
[additionalParams setObject:messageText forKey:@"messageText"];
pushMessage.additionalInfo = additionalParams;
[QBRequest sendPush:pushMessage toUsers:recipientID successBlock:^(QBResponse *response, QBMEvent *event) {
NSLog(@"Push was sent successfully to: %@", recipientID);
} errorBlock:^(QBError *error) {
NSLog(@"Push Error: %@", error);
}];
显然,我们不小心使用了一种特定方法,该方法仅将推送通知从 iOS 发送到 iOS。
在我们使用通用 QBEvent 后,它已修复
您不能使用 sendPush:toUsers:successBlock:errorBlock: 方法。
获取您的 QBMPushMessage *message 变量并使用此代码段。
QBMEvent *event = [QBMEvent event];
event.notificationType = QBMNotificationTypePush;
event.usersIDs = users;
event.type = QBMEventTypeOneShot;
NSError *error = nil;
NSData *sendData = [NSJSONSerialization dataWithJSONObject:message.payloadDict options:NSJSONWritingPrettyPrinted error:&error];
NSString *jsonString = [[NSString alloc] initWithData:sendData encoding:NSUTF8StringEncoding];
if (error) {
//error handling
}
event.message = jsonString;
[QBRequest createEvent:event successBlock:^(QBResponse * _Nonnull response, NSArray<QBMEvent *> * _Nullable events) {
} errorBlock:^(QBResponse * _Nonnull response) {
}];
我正在尝试为我们使用 quickblox 的应用程序设置推送通知。 我已经上传了正确的 iOS 证书和 Google 密钥,
我可以:
从 iOS
发送到 iOS
从 Android
发送到 Android
从 Android
发送到 iOS
但是当我尝试从 iOS
发送到 android 时,我收到 SDK 错误消息:
"No recipients. At least one user should be subscribed for APNS (Apple Push) (through SDK or REST API)"]
这很奇怪,因为我正在尝试向 GCM device
发送消息,但错误提示没有 APNS device
.
我该如何解决这个问题?什么可以中断从 iOS
推送到 Android
?
这就是我发送推送的方式
QBMPushMessage *pushMessage = [QBMPushMessage new];
pushMessage.alertBody = pushText;
NSMutableDictionary *additionalParams = [NSMutableDictionary new];
[additionalParams setObject:@1 forKey:@"isFromChat"];
if(dialogId){
[additionalParams setObject:dialogId forKey:@"dialogId"];
}
[additionalParams setObject:messageText forKey:@"messageText"];
pushMessage.additionalInfo = additionalParams;
[QBRequest sendPush:pushMessage toUsers:recipientID successBlock:^(QBResponse *response, QBMEvent *event) {
NSLog(@"Push was sent successfully to: %@", recipientID);
} errorBlock:^(QBError *error) {
NSLog(@"Push Error: %@", error);
}];
显然,我们不小心使用了一种特定方法,该方法仅将推送通知从 iOS 发送到 iOS。
在我们使用通用 QBEvent 后,它已修复
您不能使用 sendPush:toUsers:successBlock:errorBlock: 方法。 获取您的 QBMPushMessage *message 变量并使用此代码段。
QBMEvent *event = [QBMEvent event];
event.notificationType = QBMNotificationTypePush;
event.usersIDs = users;
event.type = QBMEventTypeOneShot;
NSError *error = nil;
NSData *sendData = [NSJSONSerialization dataWithJSONObject:message.payloadDict options:NSJSONWritingPrettyPrinted error:&error];
NSString *jsonString = [[NSString alloc] initWithData:sendData encoding:NSUTF8StringEncoding];
if (error) {
//error handling
}
event.message = jsonString;
[QBRequest createEvent:event successBlock:^(QBResponse * _Nonnull response, NSArray<QBMEvent *> * _Nullable events) {
} errorBlock:^(QBResponse * _Nonnull response) {
}];