Skip to content

bjulbricht/bms-pushnotifications-serversdk-swift

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BluemixPushNotifications

Swift Platform Build Status

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: 1)
	]
)

Note: BluemixPushNotifications version 0.1.x only builds with Swift DEVELOPMENT-SNAPSHOT-2016-05-03-a

Build on Linux

swift build -Xcc -fblocks -Xlinker -ldispatch

Build on OS X

swift build

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.

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 settingsExample = Notification.Settings(apns: apnsExample, gcm: gcmExample)
let targetExample = Notification.Target(deviceIds: ["device1", "device2"], platforms: [TargetPlatform.Apple, TargetPlatform.Google], tagNames: ["tag1", "tag2"], userIds: ["user1", "user2"])
let messageExample = Notification.Message(alert: "Testing BluemixPushNotifications", url: "url")

let notificationExample = Notification(message: messageExample, target: targetExample, settings: settingsExample)

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

 
 
 

Contributors

Languages

  • Swift 98.2%
  • Shell 1.8%