1

I have implemented push notifications in the app, and they work well.

But now I'm trying to figure out how to implement a custom view when you receive a push and the app is active.

i would like to replicate something like Instagram do, (see attached photo)

enter image description here

but I do not understand how, because now if the app is open and you receive a push, the app show the alert by default, with the text of the notification.

my code in didReceiveRemoteNotification is:

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

 ...

 else if (application.applicationState == UIApplicationStateActive) {

     NSString *text = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];
     NSLog(@"text remoteNot active = %@",text);

     NSString *custom = [[userInfo objectForKey:@"aps"] objectForKey:@"custom"];
     NSLog(@"custom remoteNot active = %@",custom);
  }
}

So i want to know if it is a standard behavior that you see the alert default even without writing code. And I also know how to avoid showing the alert by default, and show custom one.

Ilario
  • 5,979
  • 2
  • 32
  • 46
  • Are you using a 3rd party lib for handling push notifications? Because by default there is no alertView when you getting a push notification in foreground – arturdev Jun 27 '14 at 13:13
  • @arturdev ok i use pushwoosh, but i send push notifications also without pushwoosh.. maybe in every case pushwoosh interfere with the notification? – Ilario Jun 27 '14 at 13:20
  • Try to comment everything in that method except NSLogs, and send a push. What will happen in this case? – arturdev Jun 27 '14 at 13:23
  • @arturdev thanks for your suggestion, it's pushwoosh that show an alert when receive push notification, i don't think that because i don't implement any delegate method of this service, thank you for putting me in the right direction ;) – Ilario Jun 27 '14 at 13:52

1 Answers1

0

Nope, if you have done things correctly, a notification for the currently active app will not be shown by iOS.

I suppose you already have

[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

and that you checked that

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken

is correctly called.

Note that there is a new version of the remote notification handler:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler;

If you have that one defined, the "old" one will not be called.

Are you sure the notification is sent to the "right" app? It's easy to mix things up in development...

jcaron
  • 17,302
  • 6
  • 32
  • 46
  • thanks for your answer, the notification works very well, i'm sure, see the comment above – Ilario Jun 27 '14 at 13:21
  • Obviously it's not working very well, that's the whole point of your question... So either you're sending it to the wrong app (double check that `application:didRegisterForRemoteNotificationsWithDeviceToken:` indeed returns the token you're using), or it's not going through the right code in your app. – jcaron Jun 27 '14 at 13:45
  • it's pushwoosh that show an alert when receive push notification, i don't think that because i don't implement any delegate method of this service, thanks for your time – Ilario Jun 27 '14 at 13:52