ios - Catch push notification text on lock screen -
how can push notification text when app not run or in lock screen?
i did try:
func application(application: uiapplication, didreceiveremotenotification userinfo: [nsobject : anyobject], fetchcompletionhandler completionhandler: (uibackgroundfetchresult) -> void) { println(userinfo) // or println("something") }
but doesn't print me anything. wrong function???
didreceiveremotenotification function called condition.
- while app running , app in foreground.(alert not showing)
- if app in background , click notification on home screen
if app not run in device didreceiveremotenotification function not called, in case user click notification in home screen, identify app launched notification or not in didfinishlaunchingwithoptions
uilocalnotification *localnotif =[launchoptions objectforkey: uiapplicationlaunchoptionsremotenotificationkey];
you userinfo data in localnotif.userinfo
try in swift
func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]?) -> bool { var userinfo : nsdictionary =launchoptions[uiapplicationlaunchoptionsremotenotificationkey]; print(launchoptions); return true }