如何在应用关闭时收到通知?

时间:2016-02-02 22:22:34

标签: ios push-notification signalr appdelegate

我正在使用SignalR作为我的应用程序通知,当应用程序在后台模式下运行时,我的应用程序收到通知,但是当我关闭我的应用程序时,我无法收到通知。关闭应用程序时如何收到通知?

感谢您提前回答我:

请在下面找到我的示例代码以获取更多信息:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{


NSLog(@"notifi  %@ , %@",notification.alertBody,notification.alertTitle);
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
    UIAlertController * alert=   [UIAlertController
                                  alertControllerWithTitle:@"Title"
                                  message:@"Message"
                                  preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* yesButton = [UIAlertAction
                                actionWithTitle:@"Yes, please"
                                style:UIAlertActionStyleDefault
                                handler:^(UIAlertAction * action)
                                {
                                    //Handel your yes please button action here


                                }];
    UIAlertAction* noButton = [UIAlertAction
                               actionWithTitle:@"No, thanks"
                               style:UIAlertActionStyleDefault
                               handler:^(UIAlertAction * action)
                               {
                                   //Handel no, thanks button

                               }];

    [alert addAction:yesButton];
    [alert addAction:noButton];

    [self.window.rootViewController presentViewController:alert animated:YES completion:nil];
}

// Request to reload table view data

// Set icon badge number to zero
application.applicationIconBadgeNumber = 0;

 }

0 个答案:

没有答案