Skip to content

Instantly share code, notes, and snippets.

@sessionm-docs
Last active February 23, 2016 16:14
Show Gist options
  • Save sessionm-docs/b4569add2fe6bdc1bfb2 to your computer and use it in GitHub Desktop.
Save sessionm-docs/b4569add2fe6bdc1bfb2 to your computer and use it in GitHub Desktop.
MMC - Push Integration
//
// ExampleAppDelegate.m
// MyApp
//
//
#import "ExampleAppDelegate.h"
#import "SessionM.h"
@implementation ExampleAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Set debug mode for sandbox APNS before starting session.
#ifdef DEBUG
[SessionM sharedInstance].isDebugMode = YES;
#endif
// Assign SessionM delegate
[SessionM sharedInstance].delegate = self;
//TODO: put your app key in here.
SMStart(@"<YOUR_APP_KEY_HERE>");
// Register app to be able to receive push notifications.
[[SessionM sharedInstance] registerForRemoteNotifications];
// Pass launchOptions to SDK in case app was launched via MMC Platform push notification
BOOL isSessionMNotification = [[SessionM sharedInstance] handleRemoteNotification:launchOptions];
...
return YES;
}
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
// Ensures SessionM stored the device token.
[[SessionM sharedInstance] storeDeviceToken:deviceToken];
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
// Just like in application:didFinishLaunchingWithOptions: pass the dictionary to SessionM to handle.
BOOL isSessionMNotification = [[SessionM sharedInstance] handleRemoteNotification:userInfo];
}
// Delegate
-(void)sessionM:(SessionM *)sessionM didReceiveNotification:(SMNotificationMessageData*)notificationData {
// You can choose to display UI for the notification
// or just show the message or deep link right away.
// To display deep links or ads right away:
// [[SessionM sharedInstance] executePendingNotification];
// To use the SessionM view for any message data:
// SMDefaultMessageView *messageView = [[SessionM sharedInstaned] viewForMessageData:notificationData];
// and display:
// [messageView present];
// If you choose to display your own UI
// when you display the UI be sure to call:
// [notificationData notifyPresented];
// When user interacts with the UI to see the message or deep link call:
// [notificationData notifyTapped];
// Then to display the message or deep link call:
// [[SessionM sharedInstance] executePendingNotification];
}
-(void)sessionM:(SessionM *)sessionM handleDeepLinkString:(NSString *)deepLink {
// This delegate is called after executePendingNotification is triggered,
// the notification is of type deep link, and url is custom to developer.
// Up to developer to use deepLink however they want.
NSLog(@"Deep Link string: %@", deepLink);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment