Passer au contenu

Capacitor SDK quick start

Ce contenu n'est pas encore disponible dans votre langue.

Get started with the Pushwoosh Capacitor SDK using this quick and simple example

Prerequisites

Anchor link to

To integrate the Pushwoosh Capacitor SDK into your app, you will need the following:

Download the example project

Anchor link to

Clone the SDK repository:

Terminal window
git clone https://github.com/Pushwoosh/pushwoosh-capacitor-plugin.git

Navigate to the plugin directory:

Terminal window
cd pushwoosh-capacitor-plugin

Build the plugin

Anchor link to

Before running the example app, you need to build the Capacitor plugin.
Install plugin dependencies:

Terminal window
npm i

Build the plugin:

Terminal window
npm run build

Configure the example app

Anchor link to

Navigate to the example app directory:

Terminal window
cd example

Install the app dependencies:

Terminal window
npm i

Build the web assets:

Terminal window
npm run build

Open src/js/example.js and update the Pushwoosh.onDeviceReady call:

Pushwoosh.onDeviceReady({
projectid: "__YOUR_FCM_SENDER_ID__",
appid: "__YOUR_APP_CODE__"
});

Where:

__YOUR_APP_CODE__ is the application code from the Pushwoosh Control Panel. __YOUR_FCM_SENDER_ID__ is the Firebase project number from the Firebase Console.

1. Install CocoaPods dependencies
Anchor link to

Navigate to the iOS platform directory and install the CocoaPods dependencies:

Terminal window
cd ios/App
pod install --repo-update
cd ../..
2. Sync Capacitor to iOS
Anchor link to

After installing CocoaPods, sync the Capacitor configuration:

Terminal window
npx cap sync ios
3. Open the iOS project
Anchor link to

Open the project in Xcode:

Terminal window
npx cap open ios
3. Set the Bundle Identifier
Anchor link to

In Xcode, set the Bundle Identifier to your app’s package name (e.g., com.example.pushwoosh).

5. Add capabilities
Anchor link to

To enable Push Notifications, you need to add certain capabilities.

In the Signing & Capabilities section, add the following capabilities:

  • Push Notifications
  • Background Modes. After adding this capability, check the box for Remote notifications.
6. Set the API Token
Anchor link to

Open ios/App/App/Info.plist in Xcode and add the following entry with your Pushwoosh Device API Token:

Info.plist
<key>Pushwoosh_API_TOKEN</key>
<string>__YOUR_PUSHWOOSH_DEVICE_API_TOKEN__</string>
1. Sync Capacitor to Android
Anchor link to

Sync the Capacitor configuration to the Android platform:

Terminal window
npx cap sync android
2. Setup google-services.json
Anchor link to

Copy your google-services.json file to the android/app directory.

3. Set the package name
Anchor link to

Open android/app/build.gradle and set the applicationId to your app’s package name (e.g., com.example.pushwoosh).

4. Set the API Token
Anchor link to

Open your android/app/src/main/AndroidManifest.xml file and add the following metadata inside the <application> tag:

AndroidManifest.xml
<meta-data android:name="com.pushwoosh.apitoken" android:value="__YOUR_PUSHWOOSH_DEVICE_API_TOKEN__" />

Replace __YOUR_PUSHWOOSH_DEVICE_API_TOKEN__ with your Pushwoosh Device API Token.

5. Open the Android project
Anchor link to

Open the project in Android Studio:

Terminal window
npx cap open android

Run the project

Anchor link to
  1. Build and run the project.
  2. Tap the “Click Me!” button.
  3. Grant permission for push notifications. The device will be registered with Pushwoosh.

Send a push notification

Anchor link to

Go back to the Pushwoosh Control Panel and send a push notification to your registered device.