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 9 up to iOS 15. Make sure you always have the last Xcode available when using this library.

If you are upgrading from an older version of our library, it's always a good idea to read our Changelog file. If you migrating from 1.x.x please read the Migration Steps.

Using Cocoa Pods

Cocoa Pods is a dependency manager that let’s you easily add Objective-C/Swift fat binary libraries and frameworks in your Xcode project. To simply start using the library just add the following to your Podfile (using vi or any other text editor):

pod 'notificare-push-lib', '~> 2.7' // make sure you use the latest version available

Then make sure you install the latest pods by running the following command:

pod install

As soon as your pods are installed, make sure you close all sessions of Xcode and open the project's workspace using the following command:

open MyAmazingApp.xcworkspace

Where MyAmazingApp should be the name of your project. Finally, you will need to manually add the configuration file Notificare.plist to your project. You can get it from here.

Manual Installation

You can also choose to manually import our library to your project. Please download our latest release here. Unzip the downloaded file and drag and drop its contents into your Xcode project:

xcode drag drop lib v2

Once you've placed the folder with our library in your project, it will prompt you the following window, make sure you check the Copy items if needed option:

xcode copy folder window

Once you've done that you will see our library inside your project as follows:

xcode copied lib v2

Then go ahead and select your app's target and open the Build Phases tab:

xcode build phases

Expand the Link Binary with Libraries section and click in the plus button to start adding the necessary frameworks:

xcode add frameworks

One by one add the following frameworks to your project:

  • AVFoundation.framework
  • CoreLocation.framework
  • CoreData.framework
  • PassKit.framework (add this framework only if you are going to use native Wallet passes and marked as optional)
  • UserNotifications.framework (marked as optional)
  • CoreServices.framework (replaces MobileCoreServices.framework in Xcode 11.4)
  • CoreMedia.framework (added in SDK 2.3)
  • MessageUI.framework
  • libicucore.tbd
  • UIKit.framework
  • Foundation.framework
  • CoreGraphics.framework
  • MapKit.framework
  • SystemConfiguration.framework
  • Security.framework
  • CFNetwork.framework
  • ImageIO.framework
  • StoreKit.framework
  • WebKit.framework

After you've added all these frameworks your Link Binary with Libraries will look like this:

xcode added frameworks

Finally, in your app's target, select the Build Settings tab and search for Other Linker Flags. In that property add -ObjC, like shown below::

xcode other linker flags

Using our library in your Swift app

Thanks to Xcode you can easily bridge our Objective-C library and using it in your Swift app. After you have added the frameworks and linker flag in you project, to start using the library in your Swift project simply add a new Cocoa Touch class like shown below:

xcode add cocoa in swift

This will trigger a Xcode dialog like the one below:

xcode bridging header

By clicking Yes, Xcode will create a new file with a called AppName-Bridging-Header.h, where AppName corresponds to your own app’s name. You can now delete the Cocoa Touch file you've previously created.

Finally, in your AppName-Bridging-Header.h add the following line:

#import "NotificarePushLib.h"

Entitlements

Before you can start implementing our library code, you will need to add all the capabilities to your project. Go to your app's target and click in the tab Capabilities:

xcode capabilities tab v2

If you're going to implement remote notifications, add the Push Notifications capability:

xcode capabilities push v2

If you add the above capability, you also add the Background Modes capability and check the Remote Notifications option:

xcode capabilities bg modes v2

If you are targeting iOS 15 and using our SDK 2.7 and up, time sensitive notifications require a new capability. Add the Time Sensitive Notifications capability:

xcode capabilities time sensitive v2

If you've subscribed to the Loyalty add-on and you will handle digital cards, then you should add the Wallet capability:

xcode capabilities wallet v2

If you've subscribed to the Monetize add-on and you will sell digital products in your app, then you should add the In-App Purchase capability:

xcode capabilities in app purchases v2

If you've subscribed to the Users & Authentication add-on and you will implement OAuth2 features in your app, then you should add the Keychain Sharing capability:

xcode capabilities keychain sharing v2

If you are going to implement the NFC Reader capabilities of our library, you must add the Near Field Communication Tag Reading capability:

xcode capabilities nfc v2

If you are going to use Dynamic Links, you must add the Associated Domains capability and add all the domain prefixes you've created:

xcode capabilities associated domains v2

Finally make sure you add the Application Key and Application Secret (for both development and production) in the Notificare.plist file:

notificare plist

Import & Launch

In your AppDelegate.h start by importing the library by using the following:

#import "NotificarePushLib.h"

When using our library in Swift our library will be already accessible in all your swift files.

Please note that when using Swift you might encounter problems when using our Managed Implementation implementation as described below, specially if you will need a reference to the AppDelegate to use in your views, this approach will actually not work for Swift apps. When that is the case you will have to consider our Non-Managed Implementation as described here.

Then in your AppDelegate.h or AppDelegate.swift, make sure your declare the protocol NotificarePushLibDelegate, as follows:

@interface MyAmazingAppDelegate : UIResponder <UIApplicationDelegate, NotificarePushLibDelegate>
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, NotificarePushLibDelegate{
    ...more code
}

Then in your AppDelegate.m or AppDelegate.swift implement the following:

...more code

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    ...more code

    [[NotificarePushLib shared] initializeWithKey:nil andSecret:nil]; //You can override Notificare.plist keys here
    [[NotificarePushLib shared] setDelegate:self];
    [[NotificarePushLib shared] launch]; // Invoke this method whenever you are ready to start, this will trigger the onReady delegate method


    ...more code
}
...more code

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    ...more code

    NotificarePushLib.shared().initialize(withKey: nil, andSecret: nil) //You can override Notificare.plist keys here
    NotificarePushLib.shared().delegate = self
    NotificarePushLib.shared().launch() // Invoke this method whenever you are ready to start, this will trigger the onReady delegate method

    ...more code
}

And make sure you implement the mandatory delegate method onReady:

...more code

- (void)notificarePushLib:(NotificarePushLib *)library onReady:(nonnull NotificareApplication *)application {
    //At this point you have been assigned a temporary device identifier
    //All services subscribed can be used
}

...more code
...more code

func notificarePushLib(_ library: NotificarePushLib, onReady application: NotificareApplication) {
    //At this point you have been assigned a temporary device identifier
    //All services subscribed can be used
}

...more code

At this point, you have completed the basic setup of our library. Keep reading our implementation guides to dive deeper into each features available in our SDK.