【问题标题】:Quickblox: how to recognize which push notification sending failed in QBActionStatusDelegateQuickblox:如何识别 QBActionStatusDelegate 中哪个推送通知发送失败
【发布时间】:2014-01-17 12:17:50
【问题描述】:

我的应用程序使用 Quickblox 推送通知 API 和他们的 iOS SDK 发送推送通知。我能够使用有效负载信息在设备中成功发送和接收推送通知。

但是,现在的问题是,在发送失败的情况下,如何在QBActionStatusDelegate中识别哪个推送通知发送失败?这里假设已经发送了多个推送通知发送并同时在后台处理。

背景资料:

我正在发送这样的消息(假设在此之前已设置正确的有效负载):

QBMPushMessage *message = [[QBMPushMessage alloc] initWithPayload:payload];
[QBMessages TSendPush:message toUsers:[NSString stringWithFormat:@"%d", USERID] delegate:self];

然后我收到这样的动作状态结果:

#pragma mark QBActionStatusDelegate    
- (void)completedWithResult:(Result *)result
{
    if ([result isKindOfClass:QBMSendPushTaskResult.class]) {
        // Send Push Notifications result
        if (result.success) {
            // success
        }
        else {
            // failed

            // TODO: try to resend the push notification
            // how?
        }
}

发送失败的用例是例如设备不在网络覆盖范围内并且确实连接不良。查看此案例的日志。

<Warning>: AA MyMessagingService/QBActionStatusDelegate/completedWithResult:
QBMSendPushTaskResult failed; errors=("Connection closed due to timeout. Please 
check your internet connection."), status=0

我正在使用适用于 iOS 的 Quickblox SDK 库(最新的 git 提交:Mon Dec 30 12:42:14 2013 +0200)

【问题讨论】:

    标签: ios sdk quickblox


    【解决方案1】:

    尝试使用上下文 - 它有助于识别查询

    http://quickblox.com/developers/IOS#Performing_actions_with_context

    【讨论】:

    • 感谢@IgorKhomenko 的链接。我可能可以暂时存储发送的通知并为它们分配一个唯一的 ID,我将在 QBActionStatusDelegate 的上下文中传递该 ID。然后无论是成功还是失败,我都可以将其从“发送缓冲区”中删除或重新发送通知,直到它发送成功.. 好的,非常感谢您的回复!
    【解决方案2】:

    如果我理解正确,您可以创建一些方法,例如:

     -(void)sendPushToUser:(NSInteger)userID parameters:(NSDictionary *)params {
         //
         // get some info like payload and user id
         QBMPushMessage *message = [[QBMPushMessage alloc] initWithPayload:payload];
         [QBMessages TSendPush:message toUsers:[NSString stringWithFormat:@"%d", userId] delegate:self];
      }
    

    并在

    中调用它
       // TODO: try to resend the push notification
       // how?
    

    对于不良连接:好的做法是使用可达性(例如https://github.com/tonymillion/Reachability)。在这种情况下,失去连接后,您可以锁定发送任何请求并在连接再次出现时解锁。

    对于检查请求失败或不使用 result.success 以及 result.errors 字段。

    【讨论】:

    • 感谢@frankWhite 的可达性链接。我正在使用类似的方法来确定是否存在网络连接,但当然我可以尝试在每次发送期间使这更加系统化。但是,这并不能解决我的问题,因为我无法将发送参数(参数)放入 QBActionStatusDelegate 中,这将使我能够识别发送失败的通知。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多