swift - iOS app notifications when app is open (like whatsapp) -
im receiving notifications json , message, wanted handle notification , show user.
when app not running or in background, message shown, when app open there no notification. in fact, receive json when in didreceiveremotenotification
, want notification box whatsapp do.
like this:
i have this:
func application(application: uiapplication, didreceiveremotenotification userinfo: [nsobject : anyobject]) { print("notification received: \(userinfo)") let notification = userinfo["aps"] as? nsdictionary let message = notification?.valueforkey("alert") }
and in ´didfinishlaunchwithoptions´
let readaction = uimutableusernotificationaction() readaction.identifier = "read_identifier" readaction.title = "read" readaction.activationmode = uiusernotificationactivationmode.foreground readaction.destructive = false readaction.authenticationrequired = true let deleteaction = uimutableusernotificationaction() deleteaction.identifier = "delete_identifier" deleteaction.title = "delete" deleteaction.activationmode = uiusernotificationactivationmode.foreground deleteaction.destructive = true deleteaction.authenticationrequired = true let ignoreaction = uimutableusernotificationaction() ignoreaction.identifier = "ignore_identifier" ignoreaction.title = "ignore" ignoreaction.activationmode = uiusernotificationactivationmode.foreground ignoreaction.destructive = false ignoreaction.authenticationrequired = false let messagecategory = uimutableusernotificationcategory() messagecategory.identifier = "message_category" messagecategory.setactions([readaction, deleteaction], forcontext: uiusernotificationactioncontext.minimal) messagecategory.setactions([readaction, deleteaction, ignoreaction], forcontext: uiusernotificationactioncontext.default) let types: uiusernotificationtype = [uiusernotificationtype.badge, uiusernotificationtype.sound, uiusernotificationtype.alert] application.registerusernotificationsettings( uiusernotificationsettings( fortypes: types, categories: (nsset(array: [messagecategory])) as? set<uiusernotificationcategory>)) uiapplication.sharedapplication().registerforremotenotifications() let nottypes:uiusernotificationtype = [uiusernotificationtype.alert, uiusernotificationtype.badge, uiusernotificationtype.sound] let notesettings:uiusernotificationsettings = uiusernotificationsettings(fortypes: nottypes, categories: nil) uiapplication.sharedapplication().registerusernotificationsettings(notesettings)
hope help. all
in additional: https://github.com/bryx-inc/bryxbanner, small, nice library, written on pure swift
Comments
Post a Comment