This is a guide to help developers get up to speed with proxi.cloud iOS SDK. These step-by-step instructions are written for Objective-C developers. For instructions in Swift please click here.

Remember to set-up your application in the panel before integrating the SDK into your app. Go to https://panel.proxi.cloud and generate an API key for your app.

Demo app

Run pod try ProxicloudSDK in a terminal will open the proxi.cloud demo project.
Select the PCDemoApp target and run on device.

Alternatively you can access to the repository here.

Quickstart

Cocoapods

The easiest way to integrate the iOS SDK is via CocoaPods. If you’re new to CocoaPods, visit their getting started documentation.

cd your-project-directory
pod init
open -a Xcode Podfile

Once you’ve initialized CocoaPods, just add the proxi.cloud pod to your target:

target 'YourApp' do
	pod 'ProxicloudSDK'
end

Now you can install the dependencies in your project:

pod install
open <YourProjectName>.xcworkspace

Using the SDK

Import the ProxicloudSDK

# import <ProxicloudSDK/ProxicloudSDK.h>
# import <UserNotifications/UserNotifications.h>

Setup the PCManager with an API key and a delegate You can find your API key on the proxi.cloud panel in the “Apps” section. The proxi.cloud SDK uses an event bus for events dispatching. During setup, you pass the class instance that will receive the events as the delegate.

[[PCManager sharedManager] setApiKey:kAPIKey delegate:self];

Before starting the scanner, we need to ask permission to use the Location services. If you want to receive events while the app is innactive, you need to pass YES to the requestLocationAuthorization. If you pass NO, the app will receive events only when active.

[PCManager sharedManager] requestLocationAuthorization:YES];
Important

Be sure to add the NSLocationAlwaysAndWhenInUseUsageDescription NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription key to your plist file and the corresponding string to explain to the user why the app requires access to location.

You need also to enable the Access WiFi Information capability for your app in Xcode.

Now, we can start the SDK preferably in the location authorisation callback

SUBSCRIBE(PCEventLocationAuthorization)
{
    if (event.locationAuthorization==.authorized)
    {
        [[PCManager sharedManager] startMonitoring];
    }
}

Start receiving push notifications

Add UNUserNotificationCenterDelegate protocol to AppDelegate and register with neccessary methods

// AppDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>

//AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        center.delegate = self;
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound + UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError *_Nullable error) {
            if (!granted) {
                // print error content
            }
        }];
    return YES;
}

Action types

SDK support three action types: notification, website and deeplink. You can perform a different action for each of them in AppDelegate method (switch statement contains sample actions)

 // This function will be called if user receive notification in foreground
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
    NSString *action = nil;
    PCActionType actionType = Notification;
    if (notification.request.content.userInfo) {
        action = [PCEnums getActionUuid: notification.request.content.userInfo];
        actionType = [PCEnums getActionType: notification.request.content.userInfo];
    }
    UIAlertController *alertController;
    switch (actionType) {
        case Notification: {
                alertController = [UIAlertController alertControllerWithTitle:notification.request.content.title
                                                                      message:notification.request.content.body
                                                               preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK"
                                                             style:UIAlertActionStyleDefault
                                                           handler:^(UIAlertAction *_Nonnull actionHandler) {
                                                               // report conversion: "notification clicked"
                                                               if (action) {
                                                                   [[PCManager sharedManager] reportConversion:kPCConversionSuccessful forCampaignAction:[action copy]];
                                                               }
                                                           }];
                [alertController addAction:ok];
                [[self.window rootViewController] presentViewController:alertController animated:YES completion:^{
                }];
             
        }
        case Website:
        case DeepLink: {
            NSString *urlString = [notification.request.content.userInfo valueForKey:@"url"];
            NSURL *URL = [NSURL URLWithString:urlString];
                alertController = [UIAlertController    alertControllerWithTitle:notification.request.content.title
                                                        message:notification.request.content.body
                                                        preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *ok = [UIAlertAction  actionWithTitle:@"OK"
                                                    style:UIAlertActionStyleDefault
                                                    handler:^(UIAlertAction *_Nonnull actionHandler) {
                    // report conversion: "notification clicked"
                    if (action) {
                       [[PCManager sharedManager] reportConversion:kPCConversionSuccessful forCampaignAction:[action copy]];
                    }
                    [[UIApplication sharedApplication] openURL:URL options:@{} completionHandler:nil];
                }];
                UIAlertAction *cancel = [UIAlertAction  actionWithTitle:@"Cancel"
                                                        style:UIAlertActionStyleCancel
                                                        handler:nil];
                [alertController addAction:ok];
                [alertController addAction:cancel];
                
                [[self.window rootViewController] presentViewController:alertController animated:YES completion:^{
                }];
        }
    }
}

 // This function will be called right after user tap on the notification
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler{
    NSString *action = nil;
    PCActionType actionType = Notification;
    if (  response.notification.request.content.userInfo) {
        action = [PCEnums getActionUuid: response.notification.request.content.userInfo];
        actionType = [PCEnums getActionType: response.notification.request.content.userInfo];
    }
    switch (actionType) {
        case Notification: {
                [[PCManager sharedManager] reportConversion:kPCConversionSuccessful forCampaignAction:[action copy]];
            break;
        }
        case Website:
        case DeepLink: {
            NSString *urlString = [response.notification.request.content.userInfo valueForKey:@"url"];
            NSURL *URL = [NSURL URLWithString: urlString];
            // report conversion: "notification clicked"
            if (action) {
                [[PCManager sharedManager] reportConversion:kPCConversionSuccessful forCampaignAction:[action copy]];
            }
            [[UIApplication sharedApplication] openURL:URL options:@{} completionHandler:nil];
        }
    }
}

IDFA Support

  • Implement AdSupport library (details here) to enable support for IDFA collection

  • Pass the IDFA value to SDK using setIDFAvalue():

      if let aaid = ASIdentifierManager.shared().advertisingIdentifier {
          DDLogInfo("Successfully get AAID: \(aaid.uuidString)")
              PCManager.shared().setIDFAValue(aaid.uuidString)
              } else {
          DDLogWarn("Error with getting advertisingIdentifier, should check AAID later")
      }
    

Reporting custom events

Starting from v2.1.x the SDK allows to report custom events which then can be agreggated and analysed in the proxi.cloud platform. To use this functionality simply call the ReportEvent method when the event you wish to report occurs. The SDK will automatically add current timestamp and location (if it can be established) to the event and send it back to the proxi.cloud platform for further aggregation where it can be used to create custom reports and analytics. Below is an example showing how to report particular product view within the app.

[[PCManager sharedManager] reportEvent:@"product_viewed" withValue:@"Awesome Product 500g"];

Enabling instant messaging

To enable instant messaging via FCM (Firebase Cloud Message), configure Firebase SDK according to latest instructions. Then make sure you pass any received FCM messages to the SDK by inserting the following code into your AppDelegate

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    [[PCManager sharedManager] passFcmToPcSdk:userInfo];
}

Further information

For more information and support contact us at [email protected].

Dependencies

The proxi.cloud SDK 2.x.x requires iOS 10.0 and uses: