gpt4 book ai didi

ios - 当用户在 ios 中处于离线状态时在 quickblox 中获取消息

转载 作者:可可西里 更新时间:2023-11-01 06:14:58 25 4
gpt4 key购买 nike

我在我的项目、聊天应用程序中使用 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];
}

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

最佳答案

您必须执行正确的聊天注销。服务器应该确定您的用户处于离线状态

首先,引用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];
}

关于ios - 当用户在 ios 中处于离线状态时在 quickblox 中获取消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24930939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com