Blueshift App Configuration

Configuration is an important class where you set all the values required by the SDK to work properly. You will need to pass a valid instance of this class to initialize the Blueshift iOS SDK.

The API key is  mandatory values you need to set inside configuration object before initialization. Rest of the methods are optional. However you can make use of them to customize the SDK based on your requirements.

 

import BlueShift SDK header inside AppDelegate.h file

  • Objective-C
#import <BlueShift-iOS-SDK/BlueShift.h>    
@interface AppDelegate : UIResponder <UIApplicationDelegate, BlueShiftPushDelegate>
  • Swift
import BlueShift_iOS_SDK
class AppDelegate: UIResponder, UIApplicationDelegate, BlueShiftPushDelegate

Add the following code inside

  • Objective-C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 // Override point for customization after application launch.

 // Obtain an instance of BlueShiftConfig ...
 BlueShiftConfig *config = [BlueShiftConfig config];

 // Set the api Key for the config ...
 [config setApiKey:@"Your API Key here"];

 // Set the applications launch Options for SDK to track ...
 [config setApplicationLaunchOptions:launchOptions];

 // Set the Three Predefined DeepLinking URL's ...
 [config setProductPageURL:[NSURL URLWithString:@"Product page URL here"]];
 [config setCartPageURL:[NSURL URLWithString:@"Cart page URL here"]];
 [config setOfferPageURL:[NSURL URLWithString:@"Offer page URL here"]];

 // For Carousel push notification deep linking for each image
 [config setAppGroupID:@"Your App Group ID here"];   
    
 // Set Batch upload interval period in seconds
 [[BlueShiftBatchUploadConfig sharedInstance] setBatchUploadTimer:60.0];

 // Initialize the configuration ...
 [BlueShift initWithConfiguration:config];

 return YES;
}
  • Swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    
    // Obtain an instance of BlueShiftConfig ...
    let config: BlueShiftConfig = BlueShiftConfig()
    
    // Set the api Key for the config ...
    config.apiKey = "Your API Key here"

    // Set the applications launch Options for SDK to track ...
    config.applicationLaunchOptions = launchOptions

    // Set the Three Predefined DeepLinking URL's ...
    config.productPageURL = NSURL.init(string: "Product page URL here") as URL!
    config.cartPageURL = NSURL.init(string: "Cart page URL here") as URL!
    config.offerPageURL = NSURL.init(string: "Offer page URL here") as URL!

    // For Carousel push notification deep linking for each image
    config.appGroupID = "Your App Group ID here"       

    // Set Batch upload interval period in seconds
    BlueShiftBatchUploadConfig.sharedInstance().batchUploadTimer = 90;
    
    // Initialize the configuration ...
    BlueShift.initWithConfiguration(config)
    
    return true
}

You can read more about Batching and Real-time events here.

 

Deeplinking URL

<scheme>://<scheme_identifier>/<view_controller_identifier_1>/../<view_controller_identifi er_n>

<scheme> ­ the scheme name, this is generally your application name.

<scheme_identifier> ­ the identifier depicting the scheme ID, usually, the bundle identifier.

<view_controller_identifier> ­ the unique storyboard ID representing the view controller.

Below is an example for a url scheme which enables deeplinking through two view controllers (viewcontroller1 and viewcontroller2):

blueshiftdemoapp://com.blueshift.demoapp/viewcontroller1/viewcontroller2

 

Disable functionalities

If developer want to disable BlueShift push notification, BlueShift analytics, BlueShift analytics accesssing locations can be configured during SDK Initialization. By default SDK will enable these functionalities.

 

Objective C

// Disable BlueShift Push Notification
[config setEnablePushNotification:NO];


// Disable BlueShift Analytics accessing location
[config setEnableLocationAccess:NO];


// Disable BlueShift Analytics
[config setEnableAnalytics:NO];

 

Swift

// Disable BlueShift Push Notification
config.enablePushNotification = false


// Disable BlueShift Analytics accessing location
config.enableLocationAccess = false


// Disable BlueShift Analytics
config.enableAnalytics = false

SDK Notification Callbacks

SDK provides callbacks while user click on notification or notification action buttons (find here)

By default developer can write these callbacks in AppDelegate, but if application want to implement callbacks in separate class, application need to pass custom class reference in BlueShifConfig during SDK initialization part.

Objective C

// BlueShiftDelegates is the class for handling BlueShiftPushDelegate delegate Callbacks
BlueShiftDelegates *blueShiftDelegatge = [[BlueShiftDelegates alloc] init];
[config setBlueShiftPushDelegate:blueShiftDelegatge];

Swift

// BlueShiftDelegates is the class for handling BlueShiftPushDelegate delegate Callbacks
let blueShiftDelegatge: BlueShiftDelegates = BlueShiftDelegates()
config.blueShiftDelegatge = blueShiftDelegatge
 

Auto Integration

Call + (void) autoIntegration after calling + (void) initWithConfiguration:(BlueShiftConfig *)config for making things simpler, it will set [UIApplication sharedApplication].delegate to Instance of BlueShiftAppDelegate and it will handle all appDelegate methods, developer need not implement any appDelegate mehtods.
But if application try to accesss [UIApplication sharedApplication].delegate it will retrun BlueShiftAppDelegate instead of appDelegate if it cause any trouble go with manual integration.

 

Objective C

  • Objective-C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 // Override point for customization after application launch.

 // Obtain an instance of BlueShiftConfig ...
 BlueShiftConfig *config = [BlueShiftConfig config];

 // Set the api Key for the config ...
 [config setApiKey:@"Your API Key here"];

 // Set the applications launch Options for SDK to track ...
 [config setApplicationLaunchOptions:launchOptions];

 // Set the Three Predefined DeepLinking URL's ...
 [config setProductPageURL:[NSURL URLWithString:@"Product page URL here"]];
 [config setCartPageURL:[NSURL URLWithString:@"Cart page URL here"]];
 [config setOfferPageURL:[NSURL URLWithString:@"Offer page URL here"]];

 // For Carousel push notification deep linking for each image
 [config setAppGroupID:@"Your App Group ID here"];

 // Set Batch upload interval period in seconds
 [[BlueShiftBatchUploadConfig sharedInstance] setBatchUploadTimer:60.0];

 // Initialize the configuration ...
 [BlueShift initWithConfiguration:config];
 
 // Auto Integration
 [BlueShift autoIntegration];

 return YES;
}
 

Swift

  • Swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    
    // Obtain an instance of BlueShiftConfig ...
    let config: BlueShiftConfig = BlueShiftConfig()
    
    // Set the api Key for the config ...
    config.apiKey = "Your API Key here"

    // Set the applications launch Options for SDK to track ...
    config.applicationLaunchOptions = launchOptions

    // Set the Three Predefined DeepLinking URL's ...
    config.productPageURL = NSURL.init(string: "Product page URL here") as URL!
    config.cartPageURL = NSURL.init(string: "Cart page URL here") as URL!
    config.offerPageURL = NSURL.init(string: "Offer page URL here") as URL!

    // For Carousel push notification deep linking for each image
    config.appGroupID = "Your App Group ID here"          

    // Set Batch upload interval period in seconds
    BlueShiftBatchUploadConfig.sharedInstance().batchUploadTimer = 90;
    
    // Initialize the configuration ...
    BlueShift.initWithConfiguration(config)
    
    // Auto Integration
    BlueShift.autoIntegration()

    return true
}
 

App Delegate for Push Notifcations

In addition to configure Push notification and background event batch upload you would need to add the following to your AppDelegate.h file

  • Objective-C
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(nonnull NSData *)deviceToken {
    [[BlueShift sharedInstance].appDelegate registerForRemoteNotification:deviceToken];
}

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error {
    [[BlueShift sharedInstance].appDelegate failedToRegisterForRemoteNotificationWithError:error];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler {
    [[BlueShift sharedInstance].appDelegate handleRemoteNotification:userInfo forApplication:application fetchCompletionHandler:handler];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo {
    [[BlueShift sharedInstance].appDelegate application:application handleRemoteNotification:userInfo];
}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(nonnull UILocalNotification *)notification {
    [[BlueShift sharedInstance].appDelegate application:application handleLocalNotification:notification];
}

- (void)application:(UIApplication *) application handleActionWithIdentifier: (NSString *) identifier forRemoteNotification: (NSDictionary *) notification completionHandler: (void (^)()) completionHandler {  
    [[BlueShift sharedInstance].appDelegate handleActionWithIdentifier:identifier forRemoteNotification:notification completionHandler:completionHandler];
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    [[BlueShift sharedInstance].appDelegate appDidEnterBackground:application];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    [[BlueShift sharedInstance].appDelegate appDidBecomeActive:application];
}

The BlueShiftUserInfo class helps sending the user related details to Blueshift. If the values are set after sign in, they will be used for building the events params for all events going forward. Here is an example of setting customer id and email after user sign in.

  • Objective-C
// sign in complete
[BlueShiftUserInfo sharedUserInfo] setEmail:@"Email ID here"];
[[BlueShiftUserInfo sharedUserInfo] setRetailerCustomerID:@"Customer ID here"];

// add other user info initializations here.

// It is important to save the instance of BlueShiftUserInfo after it has been updated  
[[BlueShiftUserInfo sharedUserInfo] save];
 

Register user with BlueShift

Once BlueShift user info is saved, developer need to fire identify event ASAP.
refer identify event here

 

Permissions required

To receive push notifications, your application needs to enable Push Notification in Xcode's Project editor / Capabilities tab by switching Push Notification to ON.

To receive silent push notifications, your application needs to enable Remote Notifications in Xcode's Project Editor / Capabilities tab by switching Background Modes to ON and checking Remote Notifications.

The developer can configure the SDK to send events real-time or batched using the Blueshift Bulk Events API.

There are certain events (for eg. app_open, push_view) that pre-configured by the SDK. These events are always sent in batches. You can learn more about these events (here)

The SDK allows you to specify if an event needs to be sent real-time or in a batch. Events are sent to Blueshift by calling the SDK methods [here] (). The last argument in each method controls whether an event needs to be send real-time or in batch.

Was this article helpful?
0 out of 0 found this helpful