IOS - Using The SDK
IOS - Using The SDK
Product Manual
Current release: 8/22/2018
2 Foreworde the SDKForewordthe SDK
1 Foreword
Copyright
The contents of this manual cover material copyrighted by Selligent. Selligent reserves
all intellectual property rights on the manual, which should be treated as confidential
information as defined under the agreed upon software licence/lease terms and
conditions.
The use and distribution of this manual is strictly limited to authorized users of the
Selligent Interactive Marketing Software (hereafter the “Software”) and can only be
used for the purpose of using the Software under the agreed upon software
licence/lease terms and conditions. Upon termination of the right to use the Software,
this manual and any copies made must either be returned to Selligent or be destroyed,
at the latest two weeks after the right to use the Software has ended.
With the exception of the first sentence of the previous paragraph, no part of this
manual may be reprinted or reproduced or distributed or used in any form or by any
electronic, mechanical or other means, not known or hereafter invented, included
photocopying and recording, or in any information storage or retrieval or distribution
system, without the prior permission in writing from Selligent.
Selligent will not be responsible or liable for any accidental or inevitable damage that
may result from unauthorized access or modifications.
User is aware that this manual may contain errors or inaccuracies and that it may be
revised without advance notice. This manual is updated frequently.
2 Table of Contents
1 Foreword ................................................................................................. 2
2 Table of Contents ........................................................................................ 3
3 Intro ...................................................................................................... 5
4 Configure the APNS (Apple Push Notification Service) .................................................. 6
4.1 Enable push notifications ........................................................................... 6
4.2 Create and submit a Certificate Signing Request (CSR) ............................................ 8
4.3 Install the APNS certificate and Export the .p12 file ............................................. 10
4.4 Update your provisioning profiles in Xcode ...................................................... 11
5 Include SDK in your target ............................................................................. 12
5.1 Import the library ................................................................................. 12
5.2 Note for Swift project ............................................................................ 13
5.3 Add entries to your app .plist file................................................................. 13
5.3.1 Deep Linking ................................................................................. 13
5.3.2 Permission for camera and image gallery usage ............................................ 14
5.3.3 Permission for geo location ................................................................. 15
5.4 External framework............................................................................... 16
6 How to use the SDK .................................................................................... 17
6.1 Starting sdk ....................................................................................... 17
6.2 Push notifications ................................................................................. 19
6.2.1 Register for push notification ............................................................... 19
6.2.2 Listening and displaying the push notifications ............................................. 19
6.2.2.1 App that does not build against iOS + 10 .............................................. 19
6.2.2.2 App that build against iOS + 10 ........................................................ 20
6.2.3 Push notification helper methods........................................................... 21
6.2.4 Broadcasts (NSNotification) ................................................................. 21
6.3 In App messages .................................................................................. 23
6.3.1 Enable IAM .................................................................................. 23
6.3.2 Display IAM .................................................................................. 23
6.3.3 Broadcasts (NSNotification) ................................................................. 23
6.4 In App Content.................................................................................... 25
6.4.1 Enabling IAC ................................................................................. 25
6.4.2 Displaying IAC ............................................................................... 25
6.4.2.1 With SDK view controllers ............................................................. 25
6.4.2.2 With your own view controllers ....................................................... 27
6.4.3 Customize IAC ............................................................................... 28
4 Table of Contentse the SDKTable of Contentsthe SDK
3 Intro
The purpose of this document is to detail how to install the SDK into your app and how
to easily start using it.
• for more detailed technical reference of the sdk please refer to IOS - MobileSDK
Reference 1.7.pdf document
• for an example of implementation check the SMSDKTemplate xCode project
Configure the APNS (Apple Push Notification Service)e the SDKConfigure the APNS
6
(Apple Push Notification Service)the SDK
In the Certificates, Identifiers & Profiles page go to Identifiers under iOS Apps.
Configure the APNS (Apple Push Notification Service) 7
In the list of your app IDs select the app you want to enable the push notifications.
Edit the application services to enable the push notification.
In the list of the application services enable Push Notifications and create an SSL
Certificate for Production and/or Development.
Since iOS 10 production certificate can be used for both production and
development/sandbox environment.
Configure the APNS (Apple Push Notification Service)e the SDKConfigure the APNS
8
(Apple Push Notification Service)the SDK
In the opened window fill the User Email Address field, the Common Name and select the
Saved to disk option.
Return to the Certificate Signing Request page, click on Continue, upload the
.certSigningRequest file previously generated by the Keychain. After selecting the file,
click on Generate.
Configure the APNS (Apple Push Notification Service) 9
4.3 Install the APNS certificate and Export the .p12 file
To install the generated .cer file into the Keychain Access, double click on it, it will open
the Keychain Access with the installed certificate.
To export the .p12 file, expand the certificate, right click (or CTRL + left click) on the
certificate only and select export.
It is important to expand and select only the certificate and not the
private key associated with it. Otherwise the certificate may be invalid to
use with selligent platform.
Configure the APNS (Apple Push Notification Service) 11
starting XCode 7 some issues have been reported to apple that the
update is not always correctly refreshed and must triggered a few times
to be valid
12 Include SDK in your targete the SDKInclude SDK in your targetthe SDK
Select the lib folder (the main folder containing the header and the lib files). Depending
on your project check the option Copy item if needed and select the Create groups option.
Make sure the library has been added to your target and that it status is Required
Include SDK in your target 13
Then, go to the Build Settings of your target app, search for Other Linker Flags property
and set the value to –ObjC.
You can also create it manually by adding a header file to your project, named
[MyProjectName]-Bridging-Header.h. In your project build settings, find Swift Compiler – Code
Generation, and next to Objective-C Bridging Header add the path to your bridging header
file from the project’s root folder. So, it could be MyProject/MyProject-Bridging-Header.h or
simply MyProject-Bridging-Header.h if the file is in the project root folder.
In both case, you will need to import the SMHelper.h to expose those files to Swift. Do
it by adding this line:
#import "SMHelper.h"
You should configure correctly the plist of your app to allow this to work, by registering
a custom URL scheme
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>yourappbundle</string>
<key>CFBundleURLSchemes</key>
<array>
<string>yourscheme</string>
</array>
</dict>
</array>
You will also have to add LSApplicationQueriesSchemes key with your scheme as
string to allow your app to open the url:
<key>LSApplicationQueriesSchemes</key>
<array>
<string> appscheme </string>
</array>
By doing this you will be able to parse the URL and process it like you want.
ObjectiveC:
or when :
If all is correctly set then when the user receives a push and click it, the app will open,
an alert with the link will be displayed and the click on the link will trigger the
‘appscheme://anypage’
Since iOS 10 you must add these two keys in your plist (if not already present for your
usage) to inform correctly the user of the usage of these features:
<key>NSCameraUsageDescription</key>
<string>Allow you to participate to some promotion and contest</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Allow you to participate to some promotion and contest</string>
You will then have those two items in your plist file (the string description is shown
here just for example. It is at your convenience to describe the usage of these features
the way you want)
And when user will access camera or gallery a message will be displayed to him:
Keep in mind that this will be display one time and only if you send a
push with a button to access this feature. Otherwise the permission will
be never asked to the user and the keys are just present in plist to avoid
a potential reject from apple when app is submitted.
To use geo location, you will need a specific version of the sdk. Contact
selligent support for more information about this.
ObjectiveC
//Then:
//Create the SMManagerSetting instance
SMManagerSetting *setting = [SMManagerSetting settingWithUrl:url ClientID:clientID PrivateKey:privatKey];
//Configure location service (may not be available depending of the sdk version you have acquired)
[setting configureLocationService];
Swift
ObjectiveC
Swift
ObjectiveC:
Swift:
SMManager.sharedInstance().registerForRemoteNotification()
This can be called whenever you need to do it in your app. You can then customize
the way you inform the user before the display of iOS alert which will let the user to
allow push messages for the app on the device (the iOS alert is displayed only once).
ObjectiveC
-(void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
[[SMManager sharedInstance] didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
-(void)application:(UIApplication*)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
[[SMManager sharedInstance] didRegisterUserNotificationSettings:notificationSettings];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[[SMManager sharedInstance] didFailToRegisterForRemoteNotificationsWithError:error];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
[[SMManager sharedInstance] didReceiveRemoteNotification:userInfo];
}
Swift
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
SMManager.sharedInstance().didFailToRegisterForRemoteNotificationsWithError(error)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
SMManager.sharedInstance().didReceiveRemoteNotification(userInfo)
}
you can also implement specific delegates when your app supports
background mode (cf. IOS - MobileSDK Reference 1.7.pdf)
ObjectiveC
#import <UserNotifications/UserNotifications.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {…
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
….}
-(void)userNotificationCenter:(UNUserNotificationCenter*)center willPresentNotification:(UNNotification*) notification
withCompletionHandler:(void(^)(UNNotificationPresentationOptions options))completionHandler{
[[SMManager sharedInstance] willPresentNotification:notification];
completionHandler(UNNotificationPresentationOptionAlert);
//OR [[SMManager sharedInstance] willPresentNotification:notification withCompletionHandler:completionHandler];
//in this case the sdk will be in charge to call completionHandler with UNNotificationPresentationOptionAlert as
UNNotificationPresentationOptions
}
-(void)userNotificationCenter:(UNUserNotificationCenter*) center didReceiveNotificationResponse:(UNNotificationResponse*) response
withCompletionHandler: (void (^)()) completionHandler {
[[SMManager sharedInstance] didReceiveNotificationResponse:response];
//OR [[SMManager sharedInstance] didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
// in this case the sdk will be in charge to call completionHandler
}
Swift
import UserNotifications
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {…
let center = UNUserNotificationCenter.current()
center.delegate = self
…
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification:UNNotification, withCompletionHandler
completionHandler:@escaping(UNNotificationPresentationOptions) -> Void) {
SMManager.sharedInstance().willPresent(notification)
completionHandler(.alert) // or any UNNotificationPresentationOptions
How to use the SDK 21
when you use geolocation version of the sdk and plotprojects framework
you will mandatory have in application:didFinishLaunchingWithOptions:
to assign the delegate
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
before calling to
[[SMManager sharedInstance] startLaunchOptions:launchOptions Setting:setting]]
- (void)displayNotificationID:(NSString *)idNotification
- (void)displayLastReceivedRemotePushNotification
• Retrieve last remote push notification (return a dictionary containing id and title of
the notification)
- (NSDictionary *)retrieveLastRemotePushNotification
This can be for example associated with a library like CRToast to display
your own banner in your app.
• kSMNotification_Event_ButtonClicked:
• NSString representing a notification name you can listen to.
• An NSNotification with this name is broadcasted when the user interacts with a
remote-notification. Useful to retrieve user’s actions on a received remote-
notification, developers may listen to kSMNotification_Event_ButtonClicked
from NSNotificationCenter.
22 How to use the SDKe the SDKHow to use the SDKthe SDK
• kSMNotification_Event_WillDisplayNotification:
• NSString representing a notification name you can listen to.
• An NSNotification with this name is broadcasted shortly before displaying a
remote-notification. Primary-application may use this notification to pause any
ongoing work before the remote-notification is displayed. This notification-
name is also triggered even if you disable shouldDisplayRemoteNotification (see
SMManagerSetting).
• kSMNotification_Event_WillDismissNotification:
• NSString representing a notification name you can listen to.
• An NSNotification with this name is broadcasted shortly before dismissing the
current remote-notification. Primary-application may use this notification to
resume any paused work. (see kSMNotification_Event_WillDisplayNotification)
• kSMNotification_Event_DidReceiveRemoteNotification:
• NSString representing a notification name you can listen to.
• An NSNotification with this name is broadcasted shortly after receiving a
remote-notification. Primary-application may use this notification to decide
when to display any remote-notification
• kSMNotification_Data_ButtonData:
• NSString representing a key to retrieve an object inside NSNotification
• Use the key kSMNotification_Data_ButtonData to retrieve the object
SMNotificationButtonData from the NSNotification-name
kSMNotification_Event_ButtonClicked.
• kSMNotification_Data_RemoteNotification:
• NSString representing a key to retrieve an object inside NSNotification
• Use the key kSMNotification_Data_RemoteNotification to retrieve an
NSDictionary instance with push ID and name
ObjectiveC:
Swift:
SMManager.sharedInstance().enableInAppMessage(true)
Note: it is also possible to fetch IAM in background mode (cf. IOS - MobileSDK
Reference 1.7.pdf)
ObjectiveC:
….
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(didReceiveInAppMesage:) name:
kSMNotification_Event_DidReceiveInAppMessage object: nil];
….
-(void)didReceiveInAppMessage:(NSNotification*)notif{
NSDictionary *dict = [notif userInfo];
NSDictionary *inAppData = dict[kSMNotification_Data_InApMessaget];
}
Once your IAM retrieved you can for example create an Inbox (a table with each row
containing title of the InApp Message) and when the user clicks on the InAppMessage
a call to:
- (void)displayNotificationID:(NSString *)idNotification
with idNotification as the id of the InApp Message will allow you to display the complete
InAppMessage. (you can refer to Push notification helper methods to display In App
Messages)
The Notification will provide the app with the number of IAC's by category (key
kSMNotification_Data_InAppContent)
ObjectiveC:
-(void)anyMethodName:(NSNotification*)notif{
NSDictionary *dict = [notif userInfo];
NSArray *inAppData = dict[kSMNotification_Data_InAppContent];
}
Swift:
They all are children of SMInAppContentViewController. They can all be initialized with
one of these constructors:
26 How to use the SDKe the SDKHow to use the SDKthe SDK
ObjectiveC:
+ (instancetype) viewControllerForCategory:(NSString*)category ;
+ (instancetype) viewControllerForCategory:(NSString*)category AndOptions:(SMInAppContentStyleOptions*)options;
ObjectiveC:
Where:
• category is a NSString with the category of the IAC that must be displayed
• numberofboxes is an int used only for SMInAppContentHTMLViewController, the
maximum number of html boxes that must be displayed for a category
• options is a SMInAppContentStyleOptions which will allow you to customize your
IAC (cfr. 6.4.3 Customize IAC)
Once the sdk has provided you with the correct view controller, a bool property
(isEmpty) informs you if the sdk has found any message for the category you asked
for. If this property is false, you can then present the SMInAppContentViewController
in full screen mode (in this case, a red cross will be displayed in top right corner to
allow the dismiss of the view controller):
ObjectiveC
//example for an IAC Image that must be displayed when App become active
- (void)applicationDidBecomeActive:(UIApplication *)application {
UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;
SMInAppContentImageViewController* iacVC = [SMInAppContentImageViewController viewControllerForCategory:@"anycategory"];
if(!iacVC.isEmpty)
[tabController presentViewController:iacVC animated:YES completion:nil];
}
Swift
ObjectiveC
Swift
ObjectiveC
If you prefer to use IAC with your own UI, the sdk can provide you the necessary api
accessible with the sdk singleton [SMManager sharedInstance].
In this case, you will have to call one of these two methods to get the data:
ObjectiveC
You will then receive an NSArray of SMInAppContentMessage with all (or a certain
amount if precised by the max parameter) IAC for a category and for a type.
IMPORTANT: if you decide to use this way of interacting with IAC it is important that
you keep in mind that you will be responsible of the display of the content and you will
have to call to setInAppContentAsSeen:(SMInAppContentMessage*)inAppContent
whenever an InAppContent is showed to the user. These methods require the shown
IAC as parameter. By doing this, the sdk can process necessary consistency task and
safely inform the services about the fact the IAC has been read.
ObjectiveC
- (void) setInAppContentAsSeen:(SMInAppContentMessage*)inAppContent;
In addition to this call whenever a user interacts with an action link of the in app
content you will have to call executeLinkAction:(SMLink*)link
InAppContent:(SMInAppContentMessage*)inAppContent
ObjectiveC
providing the SMLink and the SMInAppContentMessage to allow the sdk to safely
inform the services that a specific link has been triggered by the user.
ObjectiveC
-(void)loadStyleOptions:(SMInAppContentStyleOptions*)options;
-(void)resetStyleOptions;
ObjectiveC
How to use the SDK 29
Besides these properties you still have the possibility to use UIAppearance for specific
class:
ObjectiveC
Note: For more information on IAC cf. IOS - MobileSDK Reference 1.7.pdf
How to use the SDK 31
• kSMNotification_Data_InAppContent
• NSString representing a key to retrieve an object inside NSNotification
• Use the key kSMNotification_Data_InAppContent to retrieve an NSDictionary
instance with an array of in app contents categories as key and number of in
app contents for the category as value
6.5 Geolocation
Geolocation is managed through a 3rd party framework: plotprojects.framework. To
fully use this feature, you will have to ask for a specific version of the sdk (contact
selligent for more information) and embed plotprojects.framework in your app.
Beside this, plot framework needs the presence of a config file (plotconfig.json) at the
root of your project. The content of this file will look like:
1 {
2 "publicToken": "REPLACE_ME",
3 "enableOnFirstRun": true,
4 "maxRegionsMonitored": 10,
5 "automaticallyAskLocationPermission": true
6 }
Where:
• publicToken will be the token provided for you to be able to use plot framework
• enableOnFirstRun will allow you to enable plot framework automatically if value
is set to true. Otherwise you will need to call:
whenever you will decide to enable plot framework. Another method exists
which allow you to disable the plot framework:
Once your app correctly configured, you will be able to define your campaign in plot
dashboard.
6.6 Events
• Sending any set of data to the back-end can be done with [SMManager
sharedInstance] API sendSMEvent:
• A helper method sendDeviceInfo allow you to send a specific set of device
information
These methods take in parameter a SMDeviceInfos object. This object contains
for the moment one unique property externalId:
ObjectiveC
• Default events are available for you to be used. They all inherit from SMEvent
and are configurable through their constructors:
▪ SMEventUserLogin
▪ SMEventUserLogout
▪ SMEventUserRegistration
▪ SMEventUserUnregistration
ObjectiveC :
NSLog(@"success");
} BlockFailure:^(SMFailure *failure) {
NSLog(@"failure");
}];
//Send
[SMManager sharedInstance] sendSMEvent:event];
6.6.1.2 SMEventUserregistration
This object is used to send an unregister event to the server with the e-mail of the user,
potential data and a callback.
If email is not provided you can use in the dictionary an alternate key/value field to search for
the user
ObjectiveC :
//Optional
event.shouldCache = TRUE; //not necessary as it is the default value
[event applyBlockSuccess:^(SMSuccess *success) {
NSLog(@"success");
} BlockFailure:^(SMFailure *failure) {
NSLog(@"failure");
}];
//Send
[SMManager sharedInstance] sendSMEvent:event];
6.6.2 Login/Logout
Two possible constructors:
+ (instancetype)eventWithEmail:(NSString *)mail
+ (instancetype)eventWithEmail:(NSString *)mail Dictionary:(NSDictionary<NSString*,NSString*> *)dict;
If email is not provided you can use in the dictionary an alternate key/value field to search for
the user
ObjectiveC :
NSLog(@"failure");
}];
//Send
[SMManager sharedInstance] sendSMEvent:event];
6.6.2.2 SMEventUserLogout
This object is used to send a logout event to the server with the e-mail of the user,
potential data and a callback.
If email is not provided you can use in the dictionary an alternate key/value field to
search for the user
ObjectiveC :
6.6.3 Custom
One constructor:
+ (instancetype)eventWithDictionary:(NSDictionary *)dict
ObjectiveC :
Swift:
36 How to use the SDKe the SDKHow to use the SDKthe SDK
• kSMNotification_Event_ButtonClicked
NSString representing a notification name you can listen to. An NSNotification
with this name is broadcasted when the user interacts with a remote-
notification Useful to retrieve user’s actions on a received remote-notification,
developers may listen to kSMNotification_Event_ButtonClicked from
NSNotificationCenter.
• kSMNotification_Event_WillDisplayNotification
NSString representing a notification name you can listen to. An NSNotification
with this name is broadcasted shortly before displaying a remote-notification
Primary-application may use this notification to pause any ongoing work before
the remote-notification is displayed. This notification-name is also triggered
even if you disable shouldDisplayRemoteNotification (see SMManagerSetting).
• kSMNotification_Event_WillDismissNotification
NSString representing a notification name you can listen to. An NSNotification
with this name is broadcasted shortly before dismissing the current remote-
notification Primary-application may use this notification to resume any paused
work. (see kSMNotification_Event_WillDisplayNotification)
• kSMNotification_Event_DidReceiveRemoteNotification
NSString representing a notification name you can listen to. An NSNotification
with this name is broadcasted shortly after receiving a remote-notification
Primary-application may use this notification to decide when to display any
remote-notification
• kSMNotification_Event_DidReceiveInAppMessage
NSString representing a notification name you can listen to. An NSNotification
with this name is broadcasted shortly after receiving InApp messages Primary-
application may use this notification to manage the received InApp messages
• kSMNotification_Event_DidReceiveInAppContent
NSString representing a notification name you can listen to. An NSNotification
with this name is broadcasted shortly after receiving InApp content Primary-
application may use this notification to manage the received InApp contents
38 How to use the SDKe the SDKHow to use the SDKthe SDK
• kSMNotification_Data_RemoteNotification
NSString representing a key to retrieve an object inside NSNotification Use the
key kSMNotification_Data_RemoteNotification to retrieve an NSDictionary
instance with push ID and name
• kSMNotification_Data_InAppMessage
NSString representing a key to retrieve an object inside NSNotification Use the
key kSMNotification_Data_InAppMessage to retrieve an NSDictionary instance
with an array of SMNotificationMessage
• kSMNotification_Data_InAppContent
NSString representing a key to retrieve an object inside NSNotification Use the
key kSMNotification_Data_InAppContent to retrieve an NSDictionary instance
with an array of in app contents categories as key and number of in app
contents for the category as value
6.7.3 Examples
ObjectiveC:
Swift:
//listen to broadcasting
NSNotificationCenter.defaultCenter().addObserver(self, selector: "anyMethod:", name: kSMNotification_Event_DidReceiveInAppMessage, object:
nil);
NSNotificationCenter.defaultCenter().addObserver(self, selector: "anyMethodNameButtonClicked:", name: kSMNotification_Event_ButtonClicked,
object: nil);
NSNotificationCenter.defaultCenter().addObserver(self, selector: "anyMethodNameWillDisplayNotification:", name:
kSMNotification_Event_WillDisplayNotification, object: nil);
NSNotificationCenter.defaultCenter().addObserver(self, selector: "anyMethodNameWillDismissNotification:", name:
kSMNotification_Event_WillDismissNotification, object: nil);
NSNotificationCenter.defaultCenter().addObserver(self, selector: "anyMethodNameDidReceiveRemoteNotification:", name:
kSMNotification_Event_DidReceiveRemoteNotification, object: nil);
//Notifications selectors
func anyMethodNameDidReceiveInAppMessage(notif : NSNotification){
let dict = notif.userInfo
let inAppData = dict[kSMNotification_Data_InAppMessage];
}
func anyMethodNameButtonClicked(notif : NSNotification){
let dict = notif.userInfo
let btnData : SMNotificationButtonData = dict[kSMNotification_Data_ButtonData];
}
func anyMethodNameDidReceiveRemoteNotification(notif : NSNotification){
let dict = notif.userInfo
let notifData = dict[kSMNotification_Data_RemoteNotification];
}
func anyMethodNameWillDisplayNotification(notif : NSNotification){}
func anyMethodNameWillDismissNotification(notif : NSNotification){}
40 How to use the SDKe the SDKHow to use the SDKthe SDK
6.8 Miscellaneous
6.8.1 Reload
In case you want to change the web service URL, there is a reload method to restart
the SDK.
It takes as parameter the same SMSetting object as the start method (all the values
must be set in the object, even if they did not change).
This method is for development purpose not to be used in production.
ObjectiveC:
6.8.2 LogLevel
- (void)applyLogLevel:(SMLogLevel)logLevel
ObjectiveC:
Swift:
SMManager.sharedInstance().applyLogLevel(.All)
Note: Don’t forget to check IOS - MobileSDK Reference 1.7.pdf for more detailed
information about:
• background mode
• all possible values for Constant References
How to use the SDK 41
When this is done you will need to enable App group capabilities and check
group.selligent.push in the Capabilities tab of your main app target
42 How to use the SDKe the SDKHow to use the SDKthe SDK
In the capabilities of your target enable App groups and check group.selligent.push
Rem: if your target is in swift don’t forget to set the correct path in Objective-C
bridging-header property in the build settings of your target
How to use the SDK 43
ObjectiveC
didReceiveNotificationRequest:withContentHandler:
Swift
didReceive(_:withContentHandler:)
ObjectiveC
//Then:
//Create the SMManagerSetting instance
SMManagerSetting *setting = [SMManagerSetting settingWithUrl:url ClientID:clientID PrivateKey:privatKey];
Swift
ObjectiveC
44 How to use the SDKe the SDKHow to use the SDKthe SDK
Swift
ObjectiveC
#import "SMHelper.h"
@interface NotificationService ()
@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
@end
@implementation NotificationService
self.contentHandler = contentHandler;
// Provide the request with the original notification content to the sdk and return the updated notification content
self.bestAttemptContent = [[SMManager sharedInstance] didReceiveNotificationRequest:request];
contentHandler(_bestAttemptContent);
}
- (void)serviceExtensionTimeWillExpire {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
self.contentHandler(self.bestAttemptContent);
}
@end
Swift
//Provide the request with the original notification content to the sdk and return the updated notification content
bestAttemptContent = SMManager.sharedInstance().didReceive(request)
ObjectiveC
#import "SMHelper.h"
@implementation NotificationService
// Provide the request with the original notification content to the sdk and the contentHandler
[[SMManager sharedInstance] didReceiveNotificationRequest:request WithContentHandler:contentHandler];
- (void)serviceExtensionTimeWillExpire {
// Called just before the extension will be terminated by the system.
[[SMManager sharedInstance] serviceExtensionTimeWillExpire]
}
@end
Swift
// Modify the payload contents.
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
// Init and start the sdk.
let url = "URL"
let clientID = "ClientID"
let privateKey = "privateKey"
//Provide the request with the original notification content to the sdk and the contentHandler
SMManager.sharedInstance().didReceive(request, withContentHandler: contentHandler as! (UNNotificationContent?) -> Void)
For more information on Notification service extension you can refer to apple
documentation
You will notice the creation of those files (in ObjectiveC in this example):
In the capabilities of your target enable App groups and check group.selligent.push
Now you will need to associate the Extension with Selligent Notification Category
Open the Info.plist of the extension, find the NSExtensionAttributes dictionary and set
the value of the UNNotificationExtensionCategory key to SELLIGENT_BUTTON
The storyboard will allow you to customise the display of the push notification.
If you want to keep default one please just hide the UIView created by default and
don’t set the UNNotificationExtensionDefaultContentHidden key. On the other hand
set the key to YES and customise the display of the body and title of your
notification.
For more info on Notification Content Extension please relate to apple documentation
How to use the SDK 49
ObjectiveC
didReceiveNotification:
Swift
didReceive(_:)
ObjectiveC:
#import SMHelper.h
@implementation NotificationViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any required interface initialization here.
}
50 How to use the SDKe the SDKHow to use the SDKthe SDK
- (void)didReceiveNotification:(UNNotification *)notification {
self.label.text = notification.request.content.body;
Swift:
SMManager.sharedInstance().didReceive(notification)
}
}
6.10 Changelog
- SDK 2.0
- SDK 1.9
- SDK 1.8
- SDK 1.7.1
- SDK 1.7
- SDK 1.6
o iOS 11 support
o Misc. bug corrections
o consolidate received event
o adapt user-agent of request
- SDK 1.5.2
o correct bug for in app content that must be displayed only once
- SDK 1.5.1
o correct crash bug that happens when expiration or creation date for in app content is null
- SDK 1.5
method
- SDK 1.4.5
o Store last sent user custom event and check if a modification has been done before sending
next one
- SDK 1.4.4
o compare device token based on string instead of NSData (bug swift 3 and Data class)
- SDK 1.4.3
o correction for max number of InApp Content crash when max > number of messages received
- SDK 1.4.2
- SDK 1.4.1
o bug corrections
- SDK 1.4
is used both for InApp Message and for InApp Content) possible values are :
• kSMIA_RefreshType_None
• kSMIA_RefreshType_Hourly
• kSMIA_RefreshType_Daily
- SDK 1.3
How to use the SDK 53
o To access easily all API methods, you will need to replace #import SMManager.h by #import
SMHelper.h
- SDK 1.2
o The API sendEvent: has been renamed to sendSMEvent: (This call will prevent compilation)
remote-notification when they really need it. This, then, becomes a mandatory call for receiving