SDK

Implementation

If you've completed the steps described in the Setup guides, you are now ready to implement our iOS library in your app. Our library supports iOS version 10 and up. Make sure you always have the latest iOS SDK when using this library.

If you are upgrading from an older version of our library, it's always a good idea to read our Migration guide.

Install the SDK

The Notificare SDK is compatible with apps supporting iOS 10 and above, and can be installed with Swift Package Manager or CocoaPods.

  1. If you are using the Swift Package Manager, open the menu File > Swift Packages > Add Package Dependency.
  2. In the Choose Package Repository prompt, add the following URL:
https://github.com/Notificare/notificare-sdk-ios.git
  1. Press Next and complete the remaining steps.

For more information on SPM, check their official documentation.

  1. If you haven't done so, install a recent version of CocoaPods.
  2. If you don't have an existing Podfile, run the following command to create one:
pod init
  1. Add the dependencies to your Podfile:
# Required
pod 'Notificare/NotificareKit'

# Optional modules
pod 'Notificare/NotificareInboxKit'
pod 'Notificare/NotificarePushKit'
pod 'Notificare/NotificarePushUIKit'
  1. Run the following command:
pod install
  1. From now on, use the .xcworkspace file to open your project in Xcode instead of the .xcodeproj file.

Configuration file

In order to connect your app to Notificare, you need to download the configuration file from the Dashboard and place it under your project's root folder as NotificareServices.plist. The configuration file can be downloaded by opening your Notificare application and going into the App Keys section via Menu > Settings > App Keys.

app keys v3 download

For your reference, here's what this file should look like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>APPLICATION_ID</key>
    <string>{{ YOUR APPLICATION ID }}</string>
    <key>APPLICATION_KEY</key>
    <string>{{ YOUR APPLICATION KEY }}</string>
    <key>APPLICATION_SECRET</key>
    <string>{{ YOUR APPLICATION SECRET }}</string>
</dict>
</plist>

It is recommended that you create at least two different apps in Notificare using separated environments for development and production. For each app you will have a different set of keys, resulting in two different configuration files. We recommend you to leverage Xcode's Build Phases to manage which file will be embedded in the application. You read more about it in our Customizations section.

The Notificare Delegate

While this is an optional step, by setting up your own delegate, you can listen to the ready and device_registered events. You can take the opportunity to perform additional steps when Notificare becomes ready or when the device is updated.

extension AppDelegate: NotificareDelegate {
    func notificare(_ notificare: Notificare, onReady application: NotificareApplication) {
        // At this point you have been assigned a temporary device identifier
        // All services subscribed can be used
    }

    func notificare(_ notificare: Notificare, didRegisterDevice device: NotificareDevice) {
        // At this point you know a device is registered with the Notificare API
        // This method will be called every time something changes, be it token, push enabled/disabled or other property changes
        // Use this method to keep track of device changes in your own app or act on those changes
    }
}

To let Notificare know about your delegate, you can execute the following statement:

Notificare.shared.delegate = self // where self complies with `NotificareDelegate`

Launching Notificare

Launching Notificare is as simple as calling Notificare.shared.launch(). However, before launching, you may want to consider customising some properties.

In the core module you can enable advanced logging which is helpful to diagnose problems during the development. If you have created a custom delegate, you should also set the Notificare.shared.delegate property to let Notificare know which class will handle the events.

Despite not being mandatory, a good place to launch Notificare is when the iOS application is launched. A small code sample can be found below.

class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        #if DEBUG
        // Output additional logs. Useful to diagnose problems and execution flows.
        Notificare.shared.useAdvancedLogging = true
        #endif

        // In case you want to setup your delegate.
        Notificare.shared.delegate = self

        // Launch Notificare! 🚀
        Notificare.shared.launch()
    }
}

Un-launch Notificare

Finally, it is also possible to completely remove all data for a device, both locally in your app and remotely in our servers. To do that, use the following method:

Notificare.shared.unlaunch()

After invoking this, all the device's data will be destroyed and cannot be undone. Also, invoking any other method in Notificare will fail, and the only way to start using the SDK again, is by invoking its counterpart, the launch method.