Mute Push Notifications

Magnet Message provides an easy way for developers to mute and unmute push notifications on a user's subscribed channels. When a channel is muted, an offline user will not receive push notifications as they normally would. This can be really useful when designing an app with a great user experience in mind. For example, perhaps a user may not want to receive notifications while they are at work or while they are sleeping. With Magnet Message you can add time-based mute and unmute functionality to your app on a per channel basis.

Mute Channel

To mute a channel simply call the muteUntil method on the target channel.

channel.muteUntil(nil, success: { //this channel is now muted! }, failure: { error in //print("\(error.localizedDescription)") })

Set Mute Duration

Additionally, a date can be specified to mute a channel for a specific duration. If no date is specified the channel will be muted in perpetuity.

let tomorrow = NSCalendar.currentCalendar().dateByAddingUnit(.Day, value: 1, toDate: NSDate(), options: .MatchNextTime) channel.muteUntil(tomorrow, success: { //this channel is now muted until tomorrow! }, failure: { error in //print("\(error.localizedDescription)") })

Unmute Channel

Similarly, to unmute a channel simply call unmute on the target channel.

channel.unmute(success: { //this channel is now unmuted! }, failure: { error in //print("\(error.localizedDescription)") })

Channel Mute Status

Each instance of MMXChannel contains attributes to identify a channel's "mute" status.

if channel.isMuted { //this channel is muted } else { //this channel is not muted } let formatter = NSDateFormatter() formatter.dateStyle = NSDateFormatterStyle.LongStyle formatter.timeStyle = .MediumStyle let dateString = formatter.stringFromDate(channel.mutedUntil) print("muted until \(dateString)")

Next Steps

See how to create a Private Discussion Group in your app.