Skip to content

zixzelz/bms-pushnotifications-serversdk-swift

 
 

Repository files navigation

BluemixPushNotifications

Swift Platform Build Status Codacy Badge

Summary

BluemixPushNotifications is a Swift server-side SDK for sending push notifications via Bluemix Push Notifications services.

Installation

Swift Package Manager

import PackageDescription

let package = Package(
    dependencies: [
        .Package(url: "https://github.com/ibm-bluemix-mobile-services/bluemix-pushnotifications-swift-sdk.git", majorVersion: 0, minor: 4)
	]
)
  • 0.4.x releases were tested on OSX and Linux with 3.0.1
  • 0.4.x releases were tested on OSX and Linux with DEVELOPMENT-SNAPSHOT-2016-09-07-a
  • 0.3.x releases were tested on OSX and Linux with DEVELOPMENT-SNAPSHOT-2016-06-20-a
  • 0.2.x releases were tested on OSX and Linux with DEVELOPMENT-SNAPSHOT-2016-06-06-a
  • 0.1.x releases were tested on OSX and Linux with DEVELOPMENT-SNAPSHOT-2016-05-03-a

Build on Linux

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

Usage

Import the BluemixPushNotifications framework.

import BluemixPushNotifications

Initialize with details about your Bluemix Push Notifications service.

let myPushNotifications = PushNotifications(bluemixRegion: PushNotifications.Region.US_SOUTH, bluemixAppGuid: "your-bluemix-app-guid", bluemixAppSecret: "your-push-service-appSecret")

Create a simple push notification that will broadcast to all devices.

let messageExample = Notification.Message(alert: "Testing BluemixPushNotifications", url: nil)
let notificationExample = Notification(message: messageExample, target: nil, settings: nil)

Or create a more selective push notification with specified settings that only gets sent to certain devices either by deviceIds or by userIds of users that own the devices or by device platforms or based on tag-subscriptions

let gcmExample = Notification.Settings.Gcm(collapseKey: "collapseKey", delayWhileIdle: true, payload: "payload", priority: GcmPriority.DEFAULT, sound: "sound.mp3", timeToLive: 1.0)
let apnsExample = Notification.Settings.Apns(badge: 1, category: "category", iosActionKey: "iosActionKey", sound: "sound.mp3", type: ApnsType.DEFAULT, payload: ["key": "value"])
let targetExample = Notification.Target(deviceIds: ["device1", "device2"], userIds: ["userId1", "userId2"], platforms: [TargetPlatform.Apple, TargetPlatform.Google], tagNames: ["tag1", "tag2"])
let messageExample = Notification.Message(alert: "Testing BluemixPushNotifications", url: "url")

let notificationExample = Notification(message: messageExample, target: targetExample, apnsSettings: apnsExample, gcmSettings: gcmExample)

Finally, send the Push notification.

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

License

Copyright 2016 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.

About

A server side Swift SDK for Bluemix Push Notifications Service

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 98.0%
  • Shell 2.0%