【发布时间】: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 中,您可以下载最近的活动