iOS App Push Certificate
Retrieve APN Certificate
In order for Wunderkind to send APN’s on behalf of another an APN Certificate must be obtained.
1. Open KeyChain and click Keychain Access > Certificate Assistant > Request a Certificate From a Certificate Authority
2. Complete the following fields and click Request is: Saved to Disk > Continue
3. Go to developer.apple.com/account/resources/certificates, click Identifiers, than the desired Identifier
4. Click the box next to Push Notifications, hit save, but do NOT click Configure
5. Go back to Identifiers, than go to Certificates, than click the plus
6. Select Apple Push Notification service SSL (Sandbox & Production) then Continue
7. Select the desired App ID then Continue. (Make sure to only select a single App ID)
8. Upload the .cerSigningRequest from Step 2, then download the resulting .cer
9. Open the .cer in Finder (open into KeyChain)
10. In KeyChain go to Login > My Certificates, right click the .cer and click Export "Apple Push Services...".
11. Name and save the .p12 file.
Upload APN Certificate(.p12)
Once the APN Certificate(.p12) has been obtained it must be uploaded to Wunderkind via Connect.
1. Visit https://connect.wunderkind.co/websites/ WEBSITEID /settings?tab=msdk (filling in your WebsiteID) and login. If you do not have access seek a teammate who does or reach out to Wunderkind for access.
2. Under iOS > Push Notification Certificate click Click to Upload a .p12 File, and upload your .p12.
3. After a few seconds the screen will update to show the time the certificate was uploaded.
Note: if the uploaded certificate should be removed please reach out to Wunderkind for assistance.
Wunderkind SDK AppPush Setup
Enabling AppPush Permissions
LocalInfo.plist
Add the following key.
<?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>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
</dict>
</plist>
Add AppPush Capabilities
In Xcode, select your app/project than Signing & Capabilities > + Capability > Push Notification. As well as ensure you have a Provisioning Profile set.
LocalAppDelegate.swift
The following code must be added to the app’s LocalAppDelegate.Swift. Add the code inside each function to the function that it is found in, if the function is absent, add the function as well. And ensure AppDelegate extends UNUserNotificationCenterDelegate
⚠️ If applicationDidBecomeActive is not being called, try removing UIApplicationSceneManifest from Info.plist if possible.
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions
launchOptions: [UIApplication.LaunchOptionsKey: Any]?)
-> Bool {
....
UNUserNotificationCenter.current().delegate = self
UIApplication.shared.registerForRemoteNotifications()
UNUserNotificationCenter.current()
.requestAuthorization(options: [.alert, .sound, .badge]) { granted, _ in
if granted {
Wunderkind.shared.trackAppPushOptIn()
} else {
Wunderkind.shared.trackAppPushOptOut()
}
}
UNUserNotificationCenter.current().getNotificationSettings { settings in
switch settings.authorizationStatus {
case .authorized:
Wunderkind.shared.trackAppPushOptIn()
case .denied:
Wunderkind.shared.trackAppPushOptOut()
default:
break
}
}
return true
}
func applicationDidBecomeActive(_ application: UIApplication) {
UNUserNotificationCenter.current().getDeliveredNotifications { notifications in
notifications
.filter { $0.request.content.userInfo["wunderkindPayload"] != nil }
.forEach { notification in
Wunderkind.shared.trackAppPushDelivered(appPush: notification)
}
}
}
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
Wunderkind.shared.trackAppPushTokenSet(deviceToken: deviceToken)
}
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
UIApplication.shared.applicationIconBadgeNumber -= 1
let notification = response.notification
if let wunderkindPayload = notification.request.content.userInfo["wunderkindPayload"] as? [String: Any] {
handleWunderkindItemIds(payload: wunderkindPayload)
Wunderkind.shared.trackAppPushOpened(appPush: notification)
}
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, with
@escaping (UNNotificationPresentationOptions) -> Void) {
if let wunderkindPayload = notification.request.content.userInfo["wunderkindPayload"] as? [String: Any] {
handleWunderkindItemIds(payload: wunderkindPayload)
Wunderkind.shared.trackAppPushOpened(appPush: notification)
Wunderkind.shared.trackAppPushDelivered(appPush: notification)
}
}
func handleWunderkindItemIds(payload: [String: Any]) {
guard let wunderkindItemIds = payload["wunderkindItemIds"] as? String else {
return
}
if wunderkindItemIds.contains(" , ") {
let itemIdsArray = wunderkindItemIds.components(separatedBy: " , ")
print(itemIdsArray)
// Handle the array of item IDs as needed
} else {
// Handle the single item ID case
}
}