The WonderPush Developer Hub

Welcome to the WonderPush developer hub. You'll find comprehensive guides and documentation to help you start working with WonderPush as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

Carthage Integration

Integrate WonderPush to your Xcode project using Carthage

📘

Our preferred installation method is via Cocoa Pods.

Prerequisites

Getting started with WonderPush is easy.

You'll need:

  • Xcode
  • An iOS device such as an iPhone or an iPad
  • An iOS Push Certificate (here's a how to obtain it)
  • An Xcode project your iOS application

If you haven't already, sign up for a free account on wonderpush.com.

Step 1. Create your project

Click on New Project:

Choose a name for your project and select iOS as a platform then click Create:

📘

Already have a project?

Just add the iOS platform to any existing project by going to Settings, selecting the first tab named after your project and clicking Edit. You'll be presented a form that lets you add a platform.

Step 2. Upload your push certificate

Go to Settings / Configuration, choose the iOS app tab and fill in:

  • your push certificate by clicking the Browser button,
  • the push certificate password if appropriate,
  • the Push environment (choose Development for testing with an app deployed via Xcode, and Production for an app deployed on the AppStore).

📘

Be sure to check how to use WonderPush in both Sandbox & Production.

Step 3. Create the notification service extension

In Xcode, select File / New / Target..., and choose Notification Service Extension:

Enter WonderPushNotificationServiceExtension as the name for your new target:

When Xcode prompts you to activate the new scheme, answer Cancel to keep Xcode building and debugging your app instead of the extension:

If you activate by mistake, switch back to your app's scheme from the dropdown menu located next to the play button.

Set the Deployment Target of your Notification Service Extension to 10.0:

Step 4. Integrate WonderPush to your Xcode project

Create a Cartfile at the root of your project with the following contents:

github "wonderpush/wonderpush-ios-sdk" ~> 3.0.0

In a terminal, navigate to the root of your project and type:

carthage update
This will download and build the WonderPush iOS SDK. The directory `Carthage/Build/iOS/`, should now contain those 2 files:
- `WonderPush.framework`
- `WonderPushExtension.framework`

Drag and drop these 2 files in your project, *Copy items if needed* checked at your convenience, selecting *no target*:


[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/9bd266d-integrate-drag-drop.png",
        "integrate-drag-drop.png",
        1434,
        846,
        "#313234"
      ]
    }
  ]
}
[/block]

In your project, select the target corresponding to your application and add both frameworks to the *Embedded Binaries* and *Linked Frameworks and Libraries* sections:


[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/c9af67d-integrate-app-target.png",
        "integrate-app-target.png",
        1532,
        484,
        "#28292c"
      ]
    }
  ]
}
[/block]

Select the target corresponding to the notification extension we've created previously and add `WonderPushExtension.framework` to the *Linked Frameworks and Libraries* sections:


[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/f9a1410-integrate-extension-target.png",
        "integrate-extension-target.png",
        1516,
        482,
        "#27292c"
      ]
    }
  ]
}
[/block]

Finally, add a new *Run script build phase* to your app's target:


[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/ddc7450-integrate-run-script.png",
        "integrate-run-script.png",
        1278,
        392,
        "#2d3138"
      ]
    }
  ]
}
[/block]

Paste the following script which works around an App Store submission bug triggered by universal binaries and ensures that necessary bitcode-related files and dSYMs are copied when archiving:
/usr/local/bin/carthage copy-frameworks

And setup the following input file:

  • $(SRCROOT)/Carthage/Build/iOS/WonderPush.framework
  • $(SRCROOT)/Carthage/Build/iOS/WonderPushExtension.framework

And the following output files:

  • $(DERIVED_FILE_DIR)/WonderPush.framework
  • $(DERIVED_FILE_DIR)/WonderPushExtension.framework

The result should look like this:

Step 5. Add device capabilities

Select your app's main target and, under the Capabilities tab, make sure:

  • the Background Modes capability is ON,
  • the Remote notifications background mode is checked,
  • the Push Notifications capability is ON.

Step 6. Add required code

Take note of your Client ID and Client Secret from the iOS app tab of the Settings / Configuration page:

Open your AppDelegate and add the following, adapting YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with the values you've noted above:

import WonderPush

func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        WonderPush.setClientId("YOUR_CLIENT_ID", secret: "YOUR_CLIENT_SECRET")
        WonderPush.setupDelegate(for: application)
        WonderPush.setupDelegateForUserNotificationCenter()
        return true
}
#import <WonderPush/WonderPush.h>
  
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [WonderPush setClientId:@"YOUR_CLIENT_ID" secret:@"YOUR_CLIENT_SECRET"];
    [WonderPush setupDelegateForApplication:application];
    [WonderPush setupDelegateForUserNotificationCenter];
    return YES;
}

Let's add the code that will prompt users to subscribe to push notifications. We recommend you place this code in a more suitable place in the user journey, but we'll do it at launch time for now. In your AppDelegate:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    // Prompts users to subscribe to push notifications.
    // Move this in a more suitable place in the user journey.
    WonderPush.subscribeToNotifications()
    return true
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    // Prompts users to subscribe to push notifications.
    // Move this in a more suitable place in the user journey.
    [WonderPush subscribeToNotifications];
    return YES;
}

Finally, we'll modify the code of the Notification Service Extension you created in Step 3. Replace the whole contents of NotificationService.swift or (NotificationService.h and NotificationService.m for Objective-C) with :

import WonderPushExtension

class NotificationService: WPNotificationServiceExtension {
}
#import <WonderPushExtension/WonderPushExtension.h>

@interface NotificationService : WPNotificationServiceExtension

@end
#import "NotificationService.h"

@implementation NotificationService

@end

Receive your first push!

Build & run your application and get the permission prompt you've configured:

Wait a couple of minutes and receive the default welcome notification:

👍

Congratulations, you're done!

Updated about a year ago

Carthage Integration


Integrate WonderPush to your Xcode project using Carthage

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.