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
import UserNotifications

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.shared().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.shared().requestLocationAuthorization(true)
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.

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

  @objc public func onPCEventLocationAuthorization(_ event: PCEventLocationAuthorization) {
    if event.locationAuthorization == .authorized {
      PCManager.shared().startMonitoring()
    }
  }

Start receiving push notifications

Register with neccessary methods.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        if (application.responds(to: #selector(getter: UIApplication.isRegisteredForRemoteNotifications))) {
            if #available(iOS 10, *) {
                UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
                    guard error == nil else {
                        // print error content here
                        return
                    }
                }
            } else {
                // Fallback on earlier versions iOS 9.0
                let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
                application.registerUserNotificationSettings(settings)
                application.registerForRemoteNotifications()
            }
        }
        return true
    }

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)

func application(_ application: UIApplication, didReceive notification: UILocalNotification) {

    var action: String? = nil
    var actionType: PCActionType = .Notification
    if let userInfo = notification.userInfo as? [String : Any] {
        action = PCEnums.getActionUuid(userInfo)
        actionType = PCEnums.getActionType(userInfo)
    }

    switch actionType {
    case .Notification:
        if application.applicationState == .active {
            let alertController = UIAlertController(title: notification.alertTitle, message: notification.alertBody, preferredStyle: .alert)
            let okAction = UIAlertAction(title: "OK", style: .default, handler: { alert in
                // report conversion: "notification clicked"
                if let action = action  {
                    PCManager.shared().report(.successful, forCampaignAction: action)
                }
            })
            alertController.addAction(okAction)
            self.window?.rootViewController?.present(alertController, animated: true)
        } else if let action = action {
            PCManager.shared().report(.successful, forCampaignAction: action)
        }
    case .Website, .DeepLink:
        guard let stringUrl = notification.userInfo?["url"] as? String else {
            return
        }
        guard let url = URL(string: stringUrl) else {
            return
        }
        if application.applicationState == .active {
            let alertController = UIAlertController(title: notification.alertTitle, message: notification.alertBody, preferredStyle: .alert)
            let okAction = UIAlertAction(title: "OK", style: .default) { _ in
                // report conversion: "notification clicked"
                if let action = action {
                    PCManager.shared().report(.successful, forCampaignAction: action)
                }
                UIApplication.shared.open(url)
            }
            alertController.addAction(okAction)
            self.window?.rootViewController?.present(alertController, animated: true)
        } else {
            if let action = action  {
                PCManager.shared().report(.successful, forCampaignAction: action)
            }
            UIApplication.shared.open(url)
        }
        break
    }
}

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")
      }
    

Further information

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

Dependencies

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