Quickblox:"没有收件人"错误。尝试将推送通知消息添加到简单聊天

时间:2014-06-27 18:11:19

标签: ios quickblox

在我的SplashViewController.m的viewdidload方法中,我使用此代码创建会话

更新了此部分

QBASessionCreationRequest *extendedAuthRequest = [QBASessionCreationRequest request];
    extendedAuthRequest.userLogin = @"Login";
    extendedAuthRequest.userPassword = @"password";

    // QuickBlox session creation
    [QBAuth createSessionWithExtendedRequest:extendedAuthRequest delegate:self];

在我的ChatViewController.m中,我使用这段代码订阅推送通知

// QuickBlox API queries delegate
- (void)completedWithResult:(Result *)result{

    // QuickBlox session creation  result
    if([result isKindOfClass:[QBAAuthSessionCreationResult class]]){

        // Success result
        if(result.success){

            [QBMessages TRegisterSubscriptionWithDelegate:self];

            double delayInSeconds = 1.0;
            dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
            dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                // hide splash
                [self dismissViewControllerAnimated:YES completion:nil];

                [[NSNotificationCenter defaultCenter] postNotificationName:kUserLoggedInNotification object:nil];
            });
        }else if([result isKindOfClass:QBMRegisterSubscriptionTaskResult.class]){
            // Now you can receive Push Notifications!
        }

    }else{
        NSLog(@"errors=%@", result.errors);
    }

    if(result.success && [result isKindOfClass:QBMSendPushTaskResult.class]){
        // You have successfully send push notifications

    }else{
        NSLog(@"errors=%@", result.errors);
    }
}
在sendMessage操作中

我尝试在使用此代码按下按钮时发送推送通知

// send push notification from app
    NSString *mesage = @"Hello man!";
    NSMutableDictionary *payload = [NSMutableDictionary dictionary];
    NSMutableDictionary *aps = [NSMutableDictionary dictionary];
    [aps setObject:@"default" forKey:QBMPushMessageSoundKey];
    [aps setObject:mesage forKey:QBMPushMessageAlertKey];
    [payload setObject:aps forKey:QBMPushMessageApsKey];

    QBMPushMessage *message = [[QBMPushMessage alloc] initWithPayload:payload];

    // Send push to users with id 1242713
    [QBMessages TSendPush:message toUsers:@"1242713" delegate:nil];

这是我在ChatViewController

中点击发送按钮时得到的日志
2014-06-27 13:09:54.871 sample-chat[10607:143f] -[QBChat xmppStream:didSendPresence:] -> Presence: <presence/>
2014-06-27 13:10:05.758 sample-chat[10607:143f] -[QBChat xmppStream:didSendMessage:] -> Message: <message id="4" type="chat" to="1242713-11606@chat.quickblox.com" from="1242638-11606@chat.quickblox.com"><body>test</body></message>
2014-06-27 13:10:05.759 sample-chat[10607:143f] +[QBMEvent messageToString:] -> message: {
    payload = "{\"aps\":{\"sound\":\"default\",\"alert\":\"Hello man!\"}}";
}
2014-06-27 13:10:05.759 sample-chat[10607:143f] Performing async request: 
POST https://api.quickblox.com/events.xml
headers:{
    "QB-SDK" = "iOS 1.8.6";
    "Qb-Token" = 84cc16b1fa6486d9443dcaecff84f10b380fe24c;
    "QuickBlox-REST-API-Version" = "0.1.1";
}
parameters:{
    "event[environment]" = development;
    "event[event_type]" = "one_shot";
    "event[message]" = "payload=eyJhcHMiOnsic291bmQiOiJkZWZhdWx0IiwiYWxlcnQiOiJIZWxsbyBtYW4hIn19";
    "event[notification_type]" = push;
    "event[push_type]" = apns;
    "event[user][ids]" = "1242713";
}
2014-06-27 13:10:06.036 sample-chat[10607:652b] Request finished, response:
headers:{
    "Access-Control-Allow-Origin" = "*";
    "Cache-Control" = "no-cache";
    Connection = "keep-alive";
    "Content-Type" = "application/xml; charset=utf-8";
    Date = "Fri, 27 Jun 2014 18:10:06 GMT";
    "QB-Token-ExpirationDate" = "2014-06-27 20:08:24 UTC";
    "QuickBlox-REST-API-Version" = "0.1.1";
    Server = "nginx/1.0.15";
    Status = "422 Unprocessable Entity";
    "Transfer-Encoding" = Identity;
    "X-Rack-Cache" = "invalidate, pass";
    "X-Request-Id" = 7fdb550db4da0d7833bf6391d91c134e;
    "X-Runtime" = "0.024664";
    "X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:
error:
<?xml version="1.0" encoding="UTF-8"?>
<errors>
  <error>No recipients. At least one user should be subscribed for APNS (Apple Push) (through SDK or REST API)</error>
</errors>

2 个答案:

答案 0 :(得分:0)

我只是猜测错误日志,你是否在AppDelegate注册了推送通知应用程序,即:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
]

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{

    NSString *str = [NSString stringWithFormat:@"My token is: %@", deviceToken];
}

答案 1 :(得分:0)

请显示此查询的日志

[QBMessages TRegisterSubscriptionWithDelegate:self];

如果您在此处获得了成功结果 - 此用户应该能够接收推送通知

如果你要

No recipients. At least one user should be subscribed for APNS (Apple Push) (through SDK or REST API)

这意味着身份证号为1242713的用户没有做 QBMessages TRegisterSubscriptionWithDelegate:self]; ,但确实没有取得成功

如果你使用QuickBlox - 你不需要下一行:

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

TRegisterSubscriptionWithDelegate 自动执行