ios - Send tag to OneSignal after log in -


i want send tag specific user after he/she logged in he/she can receive notifications. logged in users receive notifications. when he/she logs out, delete his/her tag. how can this?

my code in appdelegate:

let onesignal: onesignal = onesignal(launchoptions: launchoptions, appid: "<my-app-id>") {         (message, additionaldata, isactive) in          if (additionaldata != nil) {             nslog("app log additionaldata: %@", additionaldata);             let displaymessage: nsstring = nsstring(format:"notificationmessage:%@", message);              var messagetitle: nsstring = "";             if (additionaldata["discount"] != nil) {                 messagetitle = additionaldata["discount"] string             }             else if (additionaldata["bonuscredits"] != nil) {                 messagetitle = additionaldata["bonuscredits"] string;             }             else if (additionaldata["actionselected"] != nil) {                 messagetitle = nsstring(format:"pressed buttonid:%@", additionaldata["actionselected"] string);             }              var alertview: uialertview = uialertview(title: messagetitle,                 message:displaymessage,                 delegate:self,                 cancelbuttontitle:"close");              alertview.show();         }          else if (isactive) {             var alertview: uialertview = uialertview(title:"onesignal message",                 message:message,                 delegate:self,                 cancelbuttontitle:"close");             alertview.show();         }     } 

my code in loginviewcontroller:

let onesignal = onesignal() onesignal.sendtag("username", value: self.usernametextfield.text) 

the code in appdelegate working fine, users receive notifications. can receive notifications if they're not logged in.

you need use same onesignal instance appdelegate in loginviewcontroller. can make onesignal static @ class level can shared between both classes.

to delete tag can call onesignal.deletetag("username")

update: of ios 2.0 sdk methods on onesignal class static.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -