Integration: V3 Objective-C
The following information will show you how to integrate the Vibes Push Notifications SDK (v.3+) into an iOS app (Objective-C).
The Objective-C iOS Example app is also available to show you how to implement the SDK.
App Configuration
Add the following to your application:didFinishLaunchingWithOptions in your AppDelegate.m file:
[Vibes configureWithAppId:@"[YOUR APP ID HERE]"];
The Vibes SDK will notify your app of any failed or successful API calls via a delegate. When configuring the Vibes SDK, assign the delegate to any class implementing the VibesAPIDelegate protocol.
For example, you could set the delegate to your App Delegate immediately after configuration:
[Vibes configureWithAppId:@"[YOUR APP ID HERE]"];
[[Vibes shared] setWithDelegate:(id)self];
}
- (void)didRegisterDeviceWithDeviceId:(NSString *)deviceId error:(NSError *)error {
...
}
If, for any reason, you want to override the default API URL, tracked event type, storage type, advertisingID (if you use AdSupport), or the default logger, pass in an optional configuration:
NSArray *trackedEvents = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:TrackedEventTypeLaunch], [NSNumber numberWithInt:TrackedEventTypeClickthru], nil];
VibesConfiguration *config = [[VibesConfiguration alloc] initWithAdvertisingId:@"[your advertising id]" // if you're using AdSupport
apiUrl:NULL
logger:NULL // implement VibesLogger to configure your own logger
storageType:VibesStorageEnumUSERDEFAULTS // or VibesStorageEnumKEYCHAIN
trackedEventTypes:trackedEvents]; // you can also pass an empty array if you don't want to record any events.
[Vibes configureWithAppId:@"[YOUR APP ID HERE]"
configuration:(id)config];
You must reset the Vibes default endpoint if you want to use the Vibes Platform Europe instance, as defined in Technical Details.
- Default Vibes Push endpoint (US): https://public-api.vibescm.com/mobile_apps
- Vibes Push Europe endpoint (UK): https://public-api.vibescmeurope.com/mobile_apps
Registering a Device
Add the following code wherever it makes the most sense for your application.
[[Vibes shared] registerDevice];
Delegate method:
- (void)didRegisterDeviceWithDeviceId:(NSString *)deviceId error:(NSError *)error {
...
}
Unregistering a Device
Add the following code wherever it makes the most sense for your application.
[[Vibes shared] unregisterDevice];
Delegate method:
- (void)didUnregisterDeviceWithError:(NSError *)error {
...
}
Push Messaging
Registering for Push
- Register for remote notifications by following the OS Local and Remote Notification Programming guide.
- Add the following code to your app delegate.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { ... [[Vibes shared] setPushTokenFromData:deviceToken]; [[Vibes shared] registerPush]; ... }
- Delegate method:
- (void)didRegisterPushWithError:(NSError *)error { ... }
Unregistering for Push
Add the following code wherever it makes the most sense for your application.
[[Vibes shared] unregisterPush];
Delegate method:
- (void)didUnregisterPushWithError:(NSError *)error {
...
}
Update the Device Location
Add the following code wherever it makes the most sense for your application to update the location. It is not required and stores the current location with device.
[[Vibes shared] updateDeviceWithLat:latitude.doubleValue long:longitude.doubleValue];
Delegate method:
- (void)didUpdateDeviceLocationWithError:(NSError *)error {
...
}
Event Tracking
Launch, clickthru, and pushreceived events are mostly automatically tracked for you, although to properly track clickthru events, you must add the following to your AppDelegate:
# iOS 9
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
...
[[Vibes shared] receivedPushWith:userInfo at:[NSDate date]];
completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge);
}
# iOS 10
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
...
[[Vibes shared] receivedPushWith:response.notification.request.content.userInfo at:[NSDate date]];
...
}
Deep Link
Deep linking consists of adding functionality to go to a specific view, a particular section of a page, or a certain tab.
If you have deep linking enabled in your push notification setup, you can retrieve its value in the push notification payload.
{
"aps": {
"alert": {
"title": "Push Notification!",
"subtitle": "From Vibes",
"body": "You did it! "
}
},
"client_app_data": {
...
"deep_link": "XXXXXXX",
...
},
"message_uid": "9b8438b7-81cd-4f1f-a50c-4fbc448b0a53"
}
Sample code for parsing the push notification payload and navigating to the deep link:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
[self receivedPushNotifWith:response.notification.request.content.userInfo];
completionHandler();
}
// For iOS 9
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[self receivedPushNotifWith:userInfo];
completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge);
}
- (void)receivedPushNotifWith:(NSDictionary *)userInfo {
[[Vibes shared] receivedPushWith:userInfo at:[NSDate date]];
if (userInfo[@"client_app_data"][@"deep_link"]) {
// Use the deep_link value here to navigate to the appropriate view controller
}
}
Notification Sound
If your application contains a custom sound for a push notification, you can specify this sound on the Vibes Platform.
The push payload received will look like the following:
{
"aps": {
"alert": {
"title": "Push Notification!",
"subtitle": "From Vibes",
"body": "You did it! "
},
"sound":"sound.filename",
},
"message_uid": "9b8438b7-81cd-4f1f-a50c-4fbc448b0a53"
}
The sound will be played automatically if the sound file exists in your project resources.
Custom Properties
You can specify up to 10 key-value pairs on the Vibes Platform. The push payload received will look like the following:
{
"aps": {
"alert": {
"title": "Push Notification!",
"subtitle": "From Vibes",
"body": "You did it! "
}
},
"client_custom_data":{
"key1":"val1",
"key2":"val2",
....
},
"message_uid": "9b8438b7-81cd-4f1f-a50c-4fbc448b0a53"
}
In your application you can retrieve the custom data like this:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
if (response.notification.request.content.userInfo[@"client_custom_data"]) {
// Use the client_custom_data value here
}
...
}
// For iOS 9
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
if (userInfo[@"client_custom_data"]) {
// Use the client_custom_data value here
}
...
}
Badge
On the Vibes Platform, you can specify your application badge value. The push payload received will look like the following:
{
"aps": {
"alert": {
"title": "Push Notification!",
"subtitle": "From Vibes",
"body": "You did it! "
},
"badge":1,
},
"message_uid": "9b8438b7-81cd-4f1f-a50c-4fbc448b0a53"
}
Category
Push notification category is a new feature from iOS 10.+. On the Vibes Platform, you can specify the category of your push notification. The push payload received will look like the following:
{
"aps": {
"alert": {
"title": "Push Notification!",
"subtitle": "From Vibes",
"body": "You did it! "
},
"category":"some category"
},
"message_uid": "9b8438b7-81cd-4f1f-a50c-4fbc448b0a53"
}
Please check the Apple documentation for how to configure categories and actionable notifications.
Rich Media: Image, Video, Audio
From version iOS 10, you can send rich content embedded (image, video, or audio) in push notifications. Please check the Apple documentation to check how to integrate rich push capability to your application.
On the Vibes Platform, you can specify the rich content you want your customers to see.
The push payload received will look like the following:
{
"aps": {
"alert": {
"title": "Push Notification!",
"subtitle": "From Vibes",
"body": "You did it! "
},
"mutable-content":1
},
"client_app_data":{
"client_message_id":"fgfCHIUHIY8484FYIHWF",
"media_url" : "https://www.publiclyhostedurl.com"
},
"message_uid": "9b8438b7-81cd-4f1f-a50c-4fbc448b0a53"
}
Silent Push
On the Vibes Platform, you can specify to send a push notification as a silent or background push. Silent or background push notifications can be used to update a badge payload or send custom data to the app. A push notification received will look like the following:
{
"aps": {
"content-available": 1
},
"message_uid": "9b8438b7-81cd-4f1f-a50c-4fbc448b0a53"
}
Updated over 1 year ago