我希望在用户登录后将标签发送给特定的用户,以便他/她可以接收通知。只有已登录的用户才能接收通知。
当用户退出登录时,我将删除他/她的标签。
我该如何做到这一点?
我的AppDelegate中的代码:
我的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"] as String
}
else if (additionalData["bonusCredits"] != nil) {
messageTitle = additionalData["bonusCredits"] as String;
}
else if (additionalData["actionSelected"] != nil) {
messageTitle = NSString(format:"Pressed ButtonId:%@", additionalData["actionSelected"] as 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();
}
}
我的LogInViewController中的代码:
let oneSignal = OneSignal()
oneSignal.sendTag("username", value: self.usernameTextField.text)
我的appDelegate里的代码运行良好,我的用户已经能够收到通知。但是即使他们没有登录,他们也可以收到通知。