james james - 1 year ago 81
Swift Question

Suppress Parse.com ios notifications?

I am currently using Parse.com to handle push notifications. Right now I have push notifications fire when a user submits a friend request. The notification appears when the user is either in the app or not using the app at all. This is fine. However, I now have setup push notifications for when a user gets a message from another user. I want to only show the notification if the user isn't already actively chatting (this can get annoying since it appears as an Alert box in-app).

How can I fire the following push notification if the user is not using the app?

let push = PFPush()
push.setMessage("\(self.senderDisplayName) sent you a new message!")


Answer Source

You don't need to handle the push notification if the app is in active state, For that you have to comment the handlePush method, which is written in delegate method,

Like this,

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {

    //PFPush.handlePush(userInfo)//This is the method, showing the alert view while receiving the notification.

The Alternative method will be,

  • whenever your app goes to background, you have to indicate the server to send the notification.

Update- For reading the notification

You have to configure the notification payload to differentiate the notification based on type.

    "aps" : [
        "alert" : "Title",
        "type" : "NotificationType"

based on the key "type", you can disable the notification alert. Hope this helps.