No it does not show if you use above code.First of all I want to ask some questions.
Does your above code work if you use iOS 10?
Where do you call above lines of code in your class or in which method do you apply?
iOS 10 has new framework called UNUserNotification
.We have to import the UNUserNotificationCenterDelegate
for showing UILocalNotification when app is running.
The UNUserNotificationCenterDelegate protocol defines methods for
responding to actionable notifications and receiving notifications
while your app is in the foreground. You assign your delegate object
to the delegate property of the shared UNUserNotificationCenter
object. The user notification center object calls methods of your
delegate at appropriate times to deliver information.
Then when notification arrives it calls willPresentNotification
If your app is in the foreground when a notification arrives, the
notification center calls below method
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler;
Above method delivers the notification
directly to your app. If you implement this method, you can take
whatever actions are necessary to process the notification and update
your app. When you finish, execute the completionHandler block and
specify how you want the system to alert the user, if at all. If your
delegate does not implement this method, the system silences alerts as
if you had passed the UNNotificationPresentationOptionNone option to
the completionHandler block. If you do not provide a delegate at all
for the UNUserNotificationCenter object, the system uses the
notification’s original options to alert the user.
How can you show the notification?
For achieving this we have 3 options
Sound
Badge
Alert
UNNotificationPresentationOptions help us to implement this
Above is the good one to understand and do.
I preferred some answers also. They are
Show iOS notification when app is running
Displaying a stock iOS notification banner when your app is open and in the foreground?
Getting local notifications to show while app is in foreground
Notification while app is in foreground
Notification in iOS 10
Local Notification
didReceiveRemoteNotification not called , iOS 10