0
我正在使用Apple push notification services
創建一個Chat
類型的iPhone應用程序。 APN的工作正常,當用戶收到新消息時,我得到notification
。所以,我已經在我的App Delegate
類的didReceiveRemoteNotification
中彈出一個Toast
彈出。問題是,我得到的烤麪包彈出在每個View Controller
屏幕,因爲我已經在我的main window
本身添加了吐司。但你能幫我,我怎麼能隱藏這Toast
彈出我的Chat List View Controller
屏幕之一。我如何檢查當前應用程序在的窗口視圖中當前是否加載了哪個View Controller
?當應用程序在iOS中收到Apple推送通知時顯示警報彈出框
這裏是我的代碼:
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
if (application.applicationState == UIApplicationStateActive){
NSString *personName = [[userInfo valueForKey:@"aps"] valueForKey:@"user_name"];
NSString *meassge = [NSString stringWithFormat:@"New message from %@.", personName];
[[self window] makeToast:meassge duration:1.0 position:@"center"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadTheTable" object:nil];
}
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
謝謝!
@ RamyaIt不工作,我已經試過您的代碼。儘管如此,我仍然在我的ChatListViewController類中烤麪包。 – user2786 2014-09-25 06:34:12
請檢查一次topViewController是否通過放置NSLog(@「top view controller is%@」,[self topViewController])返回ChatListViewController;之前如果條件 – 2014-09-25 06:58:24
我得到[自我topViewController] SWRevealViewController在我的控制檯。其實我通過使用SWRevealViewController呈現我的ChatListViewController。 – user2786 2014-09-25 07:13:22