0

I need to show a universal custom view whenever i received a notification in a active app. I have created a view , but i am not getting how to show that! Can anyone help me out.enter image description here

Niharika
  • 1,188
  • 15
  • 37

2 Answers2

0

You have to handle the notification in the AppDelegate methods (usually application(_:​did​Receive​Remote​Notification:​fetch​Completion​Handler:​)) and launch the view in the form it can be shown in any screen of your app.

You can read the docs for UIApplicationDelegate here, section Responding to Notifications and Events.

emenegro
  • 6,901
  • 10
  • 45
  • 68
0

You will be receiving the push notification in AppDelegate's application(_:​did​Receive​Remote​Notification:​fetch​Completion​Handler:​) from here you can handle.

- (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];
}

For 2nd Option, you will need add observer and receiving method:

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

-(void)receiveNotification:(NSNotification *)notification {
    // call your view
}
nikdange_me
  • 2,949
  • 2
  • 16
  • 24