Requirements:
This guide assumes you're targeting iOS version 10 or above.
Before getting started, please make sure you are following these minimum requirements:
- XCode: version 16.2
- Cocoapods: version 1.16.1
Create an APNs auth key
Apple requires you to create an authentication key to send push notifications to iOS devices. If you already have one for your team, you can just send it to the nudge team. If you need to generate one, follow the guide here to attain one.
Preparing your app
You'll need to change a few settings before being able to integrate nudge.
Turn on your app's Push Notification and, optionally, Background Location capabilities
This can be done by selecting your app's target in the file navigator of your Xcode project and then modifying the "Signing & Capabilities":
| Basic Implementation | Location-Aware Implementation |
|
|
Add extension for rich push notification support
This enables your app to display images in nudges composed in the Larky nudge portal.
Create a new target by going to the menu bar in your Xcode project and selecting File -> New -> Target.
Select Notification Service Extension and give it a name. This can be whatever you want to name it, for example, RichPushExtension.
Once the creation of the extension is completed, Xcode will add a new folder titled with the name of your extension and including the following files in your Project Navigator:
- Info.plist
- NotificationService.swift
Importing the libraries
The nudge iOS library is available through CocoaPods or Swift Package Manager.
Cocoapods
First, install Cocoapods if you don't already have it, then follow these steps:
undefined
Create a new Empty file called Podfile in the root of your xcodeproj directory
Add the following code to your Podfile
- Replace
<YOUR_APP_NAME>with the name of your app's target: - Replace
<LIB_VERSION_NUMBER>with the current library version:
4.2.1
source 'https://cdn.cocoapods.org/' source 'https://github.com/getlarky/nudgePods.git' target '<YOUR_APP_NAME>' do use_frameworks! pod 'nudge', '<LIB_VERSION_NUMBER>' end
Open a terminal window and go to the directory of your app
This is the directory that contains the YOUR_APP_NAME.xcodeproj file.
Run the following commands:
pod install pod update
This should import the latest version of the library and create the necessary files for you. From here on out, you'll want to use the YOUR_APP_NAME.xcworkspace file instead of your usual .xcodeproj file. Quit Xcode and reopen your xcworkspace file.
Make sure User Script Sandboxing is set to NO
In your App's Project Settings, go to your App's Target Page, navigate to the Build Settings section and make check that User Script Sandboxing setting is set to NO.
Without this, you may get the following error when attempting to build the app:
nudge.framework/_CodeSignature/: mkpathat: Operation not permitted
Swift Package Manager
To add the nudge iOS library to your project as a Swift package dependency:
- In Xcode, go to File -> Add Packages.
- Use the search bar to look for github.com/getlarky/nudge-SPM.git
-
Select the package called
nudge-spmand click theAdd Packagebutton - After the package has been installed, check that the
nudgelibrary now appears in your project's Package Dependencies tab - Navigate to your project's General tab and expand the Frameworks, Libraries, and Embedded Content section and confirm that the
nudgelibrary has been added to your build target. If needed, select the "+" below this section to add it to your build target
Comments
0 comments
Article is closed for comments.