【问题标题】:get messages when user is offline in ios at quickblox当用户在 quickblox 的 ios 中离线时获取消息
【发布时间】:2014-07-24 10:12:40
【问题描述】:

我在我的项目中使用quickblox IOS的​​聊天API,聊天应用程序,现在一切正常...当用户在线时,或者应用程序未从后台删除他正在推送聊天页面中的通知和消息.. 但是当应用程序从后台删除时,他收到推送通知,但消息没有出现在聊天页面中,它只出现在推送通知中......我将我的问题发送给 quickblox 支持,他们给了我一个代码来替换我的项目,现在我的问题代码在这里:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:  (NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    cManager = [ConnectionManager sharedMannager];
    [cManager sendNetworkIdUpdate:[[DataManager sharedCenter]currentnetworkIdentifier]];

    [QBSettings setApplicationID:-----];
    [QBSettings setAuthorizationKey:@"--------"];
    [QBSettings setAuthorizationSecret:@"--------"];
    [QBSettings setAccountKey:@"--------"];

    [cManager getBlockedList];

    if (launchOptions != nil) {
        NSLog(@"Launched from push notification");
        NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        NSLog(@"%@",launchOptions);
        [[DataManager sharedCenter]setPushData:[notification valueForKeyPath:@"aps.user_info"]];
        // Do something with the notification dictionary

    }

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application{
    if ([[[DataManager sharedCenter]currentUser]userChatId]){
        [QBUsers logOutWithDelegate:[ChatService instance]];
    }
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    if ([[DataManager sharedCenter]chat_user] != nil) {
        [[QBChat instance] loginWithUser:[[DataManager sharedCenter]chat_user]];
    }
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    BOOL isLoggedIntoChat = [[QBChat instance] isLoggedIn];

    if (isLoggedIntoChat) {
        [[QBChat instance] logout];
    }
}

- (void)applicationDidBecomeActive:(UIApplication *)application{
    if ([[UIApplication sharedApplication]applicationIconBadgeNumber]>0){
        [UIApplication sharedApplication].applicationIconBadgeNumber=0;
        [cManager clearBadge];
    }

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    /*if ([[[DataManager sharedCenter]currentUser]userChatId]){
     [QBUsers logOutWithDelegate:[ChatService instance]];
     }*/

    if ([[LocalStorageService shared]messagesHistory] && [[[DataManager sharedCenter]currentUser]userId]){
        NSData *data = [NSKeyedArchiver archivedDataWithRootObject:[[LocalStorageService shared]messagesHistory]];
        [[[DataManager sharedCenter]defaults]setObject:data forKey:[NSString stringWithFormat:@"%@%@",[[[DataManager sharedCenter]currentUser]userId],kMessageHistoryBlock]];
        [[[DataManager sharedCenter]defaults]synchronize];
    }
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
    NSString* devToken = [[[[deviceToken description]
                            stringByReplacingOccurrencesOfString:@"<"withString:@""]
                           stringByReplacingOccurrencesOfString:@">" withString:@""]
                          stringByReplacingOccurrencesOfString: @" " withString: @""];
    NSLog(@"Update Token: %@",devToken);

    [cManager sendPushTokenUpdate:devToken];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
    NSLog(@"Opend from push notification");
    NSLog(@"%@",userInfo);

    UIApplicationState state = [[UIApplication sharedApplication]applicationState];
    if (state != UIApplicationStateActive){

        if ([userInfo valueForKeyPath:@"aps.user_info"]){
            [[DataManager sharedCenter]setPushData:[userInfo valueForKeyPath:@"aps.user_info"]];
            [[NSNotificationCenter defaultCenter]postNotificationName:kShowPush  object:nil];

        }

    }

    [[NSNotificationCenter defaultCenter]postNotificationName:kUpdateTables object:nil];
    [cManager clearBadge];
}

问题依旧出现! ,有什么帮助吗?

【问题讨论】:

  • 通知 kUpdateTables 有什么作用?您在 applicationDidReceiveRemoteNotification 中的代码在哪里更新应该在聊天中显示的内容?
  • 您好,根据好友请求更新用户表。问题是如果应用程序被终止(完全关闭),应用程序不会收到来自 QuickBlox 的离线消息。
  • @LenaBru 嗨,它是根据好友请求更新用户表。问题是如果应用程序被终止(完全关闭),应用程序不会收到来自 QuickBlox 的离线消息
  • 你能改变方法 application:didReceiveRemoteNotification: with - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler NS_AVAILABLE_IOS (7_0);另一种选择是,在您的应用程序 WillEnterForeground 中,您可以下载最近的活动

标签: ios iphone quickblox


【解决方案1】:

您必须正确退出聊天。服务器应该确定您的用户处于离线状态

首先,参考Chat in background mode文档http://quickblox.com/developers/SimpleSample-chat_users-ios#Chat_in_background_mode

尝试在 applicationWillTerminate 和 applicationDidEnterBackground 中退出聊天:

- (void)applicationWillTerminate:(UIApplication *)application
{
    [[QBChat instance] logout];
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [[QBChat instance] logout];
}

【讨论】:

  • 嗨,我做了更改,但没有用!我在哪里可以给你发源来帮我检查?或者如果你想要钱
  • 您在这些消息中设置了正文还是为空?请发布您的代码如何发送消息
  • 看......我很困惑......我可以给你发一个源来检查我的代码吗?我在这里:facebook.com/m3lawe
  • @IgorKhomenko 我也面临同样的问题。我在应用程序处于后台时注销并在“applicationWillEnterForeground”中再次登录,但我没有收到离线消息。你能帮帮我吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-05-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-07
  • 2014-11-13
相关资源
最近更新 更多