Creating a Push Message

With Magnet Message it is easy to implement push notifications into your apps.

  1. Please visit Set up APNS for instructions on how to enable your app to use push notifications.
  2. Creating your First App contains instructions for initializing Magnet Message.

Send Push Messages

Once Magnet Message has been initialized and APNS has been set up, push notifications can be sent to recipients (MMUsers) using a MMXPushMessage object. Recipients will receive the notifications on all of their devices they have enabled. A recipient can have multiple devices (Android, iOS, or both). Magnet Message will seamlessly send notifications to the correct devices.

Example Push 1:

//retrieve user(s) [MMUser usersWithUserNames:@[@"SOME_USER_NAME"] success:^(NSArray *users) { if (users.count > 0) { //create message MMXPushMessage *pmsg = [MMXPushMessage pushMessageWithRecipient:users.firstObject body:@"Hello World!"]; //send push [pmsg sendPushMessage:^() { NSLog(@"Success"); } failure:^(NSError * error) { NSLog(@"Error sending push %@", error.localizedDescription); }]; } } failure:^(NSError * error) { NSLog(@"Error retreiving user(s) %@", error.localizedDescription); }];


Example Push 2:

//retrieve user(s) [MMUser usersWithUserNames:@[@"SOME_USER_NAME"] success:^(NSArray *users) { if (users.count > 0) { //create message MMXPushMessage *pmsg = [MMXPushMessage pushMessageWithRecipient:users.firstObject body:@"Hello World!" title:@"New Message" sound:@"default" badge:@(10) userDefinedObjects:@{@"UserDefineKey1" : @"UserDefineValue1", @"UserDefineKey2" : @"UserDefineValue2"}]; //send push [pmsg sendPushMessage:^() { NSLog(@"Success"); } failure:^(NSError * error) { NSLog(@"Error sending push %@", error.localizedDescription); }]; } } failure:^(NSError * error) { NSLog(@"Error retreiving user(s) %@", error.localizedDescription); }];


Receive Push Messages

MMXPushMessage provides a simple way to recreate and access a push message's content from the userInfo dictionary that is returned in the App Delegate.

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { //recreate message MMXPushMessage *msg = [[MMXPushMessage alloc] initWithPushUserInfo:userInfo]; NSString *body = msg.body ? msg.body : @""; NSString *title = msg.title ? msg.title : @"No Title"; NSLog(@"Body:%@ title:%@ \nContent Dictionary %@", body, title, msg.messageContent); }