Home

Awesome

IBM Cloud Mobile Services - Server side Swift SDK for IBM Cloud Push Notifications Service

Swift Platform Build Status Codacy Badge Coverage Status

The IBM Cloud Push Notifications service provides a unified push service to send real-time notifications to mobile and web applications. The Swift server-side SDK for sending push notifications through the IBM Cloud Push Notifications services.

Ensure that you go through IBM Cloud Push Notifications service documentation before you start.

Contents

Installation

Swift Package Manager

import PackageDescription
let package = Package(
    dependencies: [
        .package(url: "https://github.com/ibm-bluemix-mobile-services/bluemix-pushnotifications-swift-sdk.git", .upToNextMajor(from: "1.6.0"))
	]
)

Build on Linux

sudo apt-get update // not required on Mac
swift build -Xcc -fblocks -Xlinker -rpath -Xlinker $(pwd)/.build/debug/

Usage

Simple notification

Complete the following steps:

  1. Import the IBMPushNotifications framework.

    import IBMPushNotifications
    

Note: For Syndicated use the overrideServerHost param of PushNotifications before initliazong the PushNotifications . Eg: PushNotifications.overrideServerHost = "https://syndicated.region.net"

  1. Initialize with details about your IBM Cloud Push Notifications service.
  1. Create a simple push notification that will broadcast to all devices.

    let messageExample = Notification.Message(alert: "Testing IBMPushNotifications")
    let notificationExample = Notification(message: messageExample)
    
  2. Send the Push notification using the method:

    myPushNotifications.send(notification: notificationExample) { (data, status, error) in
      if error != nil {
        print("Failed to send push notification. Error: \(error!)")
      }
    }
    

Note: If you are using the APIKEY for Initialisation kindly call getAuthToken() , before sending any notification. This will add an Authorization header for the request.

To create a more selective push notification with specified settings that is only sent to certain devices either by deviceIds or userIds or by device platforms or based on tag-subscriptions, or to set GCM and APNs features - there are optional parameters that you can use in the corresponding initializers.

Send Bulk push notifications

To send the bulk push notifications of the following,

myPushNotifications.sendBulk(notification: [notificationExample,notificationExample1,notificationExample2]) { (data, status, error) in
	if error != nil {
		print("Failed to send push notification. Error: \(error!)")
	}
}

Notification options

Target

In Target, you pass the following values:

Note: Do not use userIds, tagNames, platforms and deviceIds together.

Settings

Settings can contain any of the following types:

APNs

APNs settings can have the following parameters:

GCM

GCM settings can have the following parameters:

FirefoxWeb

FirefoxWeb settings can have the following parameters:

ChromeWeb

ChromeWeb settings can have the following parameters:

SafariWeb

SafariWeb settings can have the following parameters:

let safariSettings = Notification.Settings.SafariWeb(title: "IBM Cloud Push Notifications", urlArgs: ["https://IBMCloud.net"], action: "View")
ChromeAppExt

ChromeAppExt settings can have the following parameters:

API documentation

Find the API documentation here - https://ibm-bluemix-mobile-services.github.io/API-docs/server-SDK/IBMPushNotifications/index.html

Samples and videos

Learning more

Connect with IBM Cloud

Twitter | YouTube | Blog | Facebook |

======================= Copyright 2020-21 IBM Corp.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.