在活动应用程序中收到通知时显示客户视图

时间:2017-03-15 07:26:23

标签: ios objective-c push-notification

每当我在活动应用中收到通知时,我都需要显示通用的自定义视图。 我创建了一个视图,但我没有得到如何显示! 任何人都可以帮助我。enter image description here

2 个答案:

答案 0 :(得分:0)

您必须使用AppDelegate方法(通常为application(_:​did​Receive​Remote​Notification:​fetch​Completion​Handler:​))处理通知,然后以可在应用的任何屏幕中显示的形式启动视图。

您可以阅读UIApplicationDelegate here的文档,回应通知和事件部分。

答案 1 :(得分:0)

您将从此处接收AppDelegate应用程序中的推送通知(_:确实接收远程通知:获取完成处理程序:):

- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))handler
{
 // 1. You can call your universal view from here

               OR

 // 2. You can post this local notification with information
 NSDictionary *userInfo = [NSDictionary dictionaryWithObject:myObject forKey:@"info"];
 [[NSNotificationCenter defaultCenter] postNotificationName:@"showNotification"
                                                     object:nil
                                                   userInfo:userInfo];
}

对于第二选项,您需要添加观察者和接收方法:

[[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(receiveNotification:) 
        name:@"showNotification"
        object:nil];

-(void)receiveNotification:(NSNotification *)notification {
    // call your view
}