<commit_before>IBM Bluemix Mobile Services - Client SDK Swift Push
===================================================

[![Build Status](https://travis-ci.org/ibm-bluemix-mobile-services/bms-clientsdk-swift-push.svg?branch=master)](https://travis-ci.org/ibm-bluemix-mobile-services/bms-clientsdk-swift-push)
[![Build Status](https://travis-ci.org/ibm-bluemix-mobile-services/bms-clientsdk-swift-push.svg?branch=development)](https://travis-ci.org/ibm-bluemix-mobile-services/bms-clientsdk-swift-push)


This is the Push component of the Swift SDK for [IBM Bluemix Mobile Services](https://console.ng.bluemix.net/docs/mobile/index.html).


## Contents

This package contains the Push components of the Swift SDK.
* Push Registration
* Subscribing and Unsubcribing for Tags


## Requirements

* iOS 8.0+
* Xcode 7


## Installation

The Bluemix Mobile Services Swift SDKs are available via [Cocoapods](http://cocoapods.org/) and [Carthage](https://github.com/Carthage/Carthage).


### Cocoapods
To install BMSCore using Cocoapods, add it to your Podfile:

```ruby
use_frameworks!

target 'MyApp' do
    platform :ios, '8.0'
    pod 'BMSCore'
    pod 'BMSPush'
end
```
From the Terminal, go to your project folder and install the dependencies with the following command:


####Swift 2.3

Before running the `pod install` command, make sure to use Cocoapods version 1.1.0.beta.1.

####Swift 3.0

Before running the `pod install` command, make sure to use Cocoapods version 1.1.0.beta.1.

For apps built with Swift 3.0, you may receive a prompt saying "Convert to Current Swift Syntax?" when opening your project in Xcode 8 (following the installation of BMSCore). Always choose the Later option.

This will installs your dependencies and creates a new Xcode workspace.
***Note:*** Ensure that you always open the new Xcode workspace, instead of the original Xcode project file:

```
   MyApp.xcworkspace
```

### Carthage
To install BMSPush using Carthage, add it to your Cartfile:

```
github "ibm-bluemix-mobile-services/bms-clientsdk-swift-push"
```

Then run the `carthage update` command. Once the build is finished, drag `BMSPush.framework`,`BMSCore.framework` and `BMSAnalyticsAPI.framework` into your Xcode project.

To complete the integration, follow the instructions [here](https://github.com/Carthage/Carthage#getting-started).

####Xcode 8

Carthage currently is not supported for BMSCore in Xcode 8 beta. Please use Cocoapods instead.

## Enabling iOS applications to receive push notifications

##### Reference the SDK in your code.

```
import BMSPush
import BMSCore
```
#### Initializing the Core SDK

```
let myBMSClient = BMSClient.sharedInstance

//Swift3

myBMSClient.initializeWithBluemixAppRoute(bluemixAppRoute: "https://example.mybluemix.net", bluemixAppGUID: "1234", bluemixRegion: "Location where your app Hosted")

// Swift 2.3 or Older

myBMSClient.initializeWithBluemixAppRoute("bluemixAppRoute", bluemixAppGUID: "APPGUID", bluemixRegion:"Location where your app Hosted")

myBMSClient.defaultRequestTimeout = 10.0 // Timput in seconds

```
***bluemixAppRoute***

Specifies the route that is assigned to the server application that you created on Bluemix.

***bluemixAppGUID***

Specifies the unique key that is assigned to the application that you created on Bluemix. This value is
case-sensitive.

***bluemixRegion***

Specifies the location where the app hosted. You can use one of three values - `BMSClient.REGION_US_SOUTH`, `BMSClient.REGION_UK` and `BMSClient.REGION_SYDNEY`.

#### Initializing the Push SDK

```
let push =  BMSPushClient.sharedInstance

//Swift 3
 push.initializeWithAppGUID(appGUID: "")

 //Swift 2.3 or Older
push.initializeWithAppGUID("appGUID")
```
***appGUID***

The Push app GUID value.

For *userId* based notifiction initialize the `BMSPush` with `clientSecret` .

```
let push =  BMSPushClient.sharedInstance

//Swift 3

push.initializeWithAppGUID(appGUID: "your push appGUID", clientSecret:"your push client secret")

//Swift2.3 or Older
push.initializeWithAppGUID("appGUID", clientSecret:"clientSecret")
```

***appGUID***

The Push app GUID value.

***clientSecret***

The Push client secret value.

#### Registering iOS applications and devices

Add this code to registering the app for push notification in APNS,

```

//swift3 
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
UIApplication.sharedApplication().registerForRemoteNotifications()

```    
After the token is received from APNS, pass the token to Push Notifications as part of the
 ***didRegisterForRemoteNotificationsWithDeviceToken*** method.

```
 func application (application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData){

   let push =  BMSPushClient.sharedInstance
   push.initializeWithAppGUID("pushAppGUID")
   push.registerWithDeviceToken(deviceToken) { (response, statusCode, error) -> Void in

        if error.isEmpty {

            print( "Response during device registration : \(response)")

            print( "status code during device registration : \(statusCode)")
        }
        else{
            print( "Error during device registration \(error) ")

            Print( "Error during device registration \n  - status code: \(statusCode) \n Error :\(error) \n")
        }
    }

}
```

For *user Id* based notification, the register method will accept one more parameter - *userId*


```
func application (application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData){

    let push =  BMSPushClient.sharedInstance
    push.initializeWithAppGUID("pushAppGUID", clientSecret:"clientSecret")
    push.registerWithDeviceToken(deviceToken, WithUserId: "your user id") { (response, statusCode, error) -> Void in

        if error.isEmpty {

            print( "Response during device registration : \(response)")

            print( "status code during device registration : \(statusCode)")
        }
        else{
            print( "Error during device registration \(error) ")

            Print( "Error during device registration \n  - status code: \(statusCode) \n Error :\(error) \n")
        }
    }

}
```

**WithUserId**

the User Id value you want to register in the push service

>**Note**: If userId is provided the client secret value must be provided.


#### Retrieve Available Tags and register for Tags

##### Retrieve Available tags

The ***retrieveAvailableTagsWithCompletionHandler*** API returns the list of available tags to which the device
can subscribe. After the device is subscribed to a particular tag, the device can receive any push notifications
that are sent for that tag.

Call the push service to get subscriptions for a tag.

Copy the following code snippets into your Swift mobile application to get a list of available tags to which the
device can subscribe.

```
push.retrieveAvailableTagsWithCompletionHandler({ (response, statusCode, error) -> Void in

    if error.isEmpty {

        print( "Response during retrieve tags : \(response)")

        print( "status code during retrieve tags : \(statusCode)")
    }
    else{
        print( "Error during retrieve tags \(error) ")

        Print( "Error during retrieve tags \n  - status code: \(statusCode) \n Error :\(error) \n")
    }
}
```
##### Subscribe to Available tags

```
push.subscribeToTags(response, completionHandler: { (response, statusCode, error) -> Void in

    if error.isEmpty {

        print( "Response during Subscribing to tags : \(response?.description)")

        print( "status code during Subscribing tags : \(statusCode)")
    }
    else {

        print( "Error during subscribing tags \(error) ")

        Print( "Error during subscribing tags \n  - status code: \(statusCode) \n Error :\(error) \n")
    }
}
```

##### Retrieve Subscribed tags

```
push.retrieveSubscriptionsWithCompletionHandler { (response, statusCode, error) -> Void in

    if error.isEmpty {

        print( "Response during retrieving subscribed tags : \(response?.description)")

        print( "status code during retrieving subscribed tags : \(statusCode)")
    }
    else {

        print( "Error during retrieving subscribed tags \(error) ")

        Print( "Error during retrieving subscribed tags \n  - status code: \(statusCode) \n Error :\(error) \n")
    }
}
```
#### unsubscribing tags

Use the following code snippets to allow your devices to get unsubscribe
from a tag.

```
push.unsubscribeFromTags(response, completionHandler: { (response, statusCode, error) -> Void in

    if error.isEmpty {

        print( "Response during unsubscribed tags : \(response?.description)")

        print( "status code during unsubscribed tags : \(statusCode)")
    }
    else {
        print( "Error during  unsubscribed tags \(error) ")

        print( "Error during unsubscribed tags \n  - status code: \(statusCode) \n Error :\(error) \n")
    }
}
```
#### Unregistering the Device from Bluemix Push Notification

Use the following code snippets to Unregister the device from Bluemix Push Notification

```
push.unregisterDevice({ (response, statusCode, error) -> Void in

    if error.isEmpty {

        print( "Response during unregistering device : \(response)")

        print( "status code during unregistering device : \(statusCode)")
    }
    else{
        print( "Error during unregistering device \(error) ")

        print( "Error during unregistering device \n  - status code: \(statusCode) \n Error :\(error) \n")
    }
}
```

###Learning More
* Visit the **[Bluemix Developers Community](https://developer.ibm.com/bluemix/)**.

* [Getting started with IBM MobileFirst Platfrom for iOS](https://www.ng.bluemix.net/docs/mobile/index.html)

###Connect with Bluemix

[Twitter](https://twitter.com/ibmbluemix) |
[YouTube](https://www.youtube.com/playlist?list=PLzpeuWUENMK2d3L5qCITo2GQEt-7r0oqm) |
[Blog](https://developer.ibm.com/bluemix/blog/) |
[Facebook](https://www.facebook.com/ibmbluemix) |
[Meetup](http://www.meetup.com/bluemix/)


=======================
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.
<commit_msg>Added installation requirements to README<commit_after>IBM Bluemix Mobile Services - Client SDK Swift Push
===================================================

[![Build Status](https://travis-ci.org/ibm-bluemix-mobile-services/bms-clientsdk-swift-push.svg?branch=master)](https://travis-ci.org/ibm-bluemix-mobile-services/bms-clientsdk-swift-push)
[![Build Status](https://travis-ci.org/ibm-bluemix-mobile-services/bms-clientsdk-swift-push.svg?branch=development)](https://travis-ci.org/ibm-bluemix-mobile-services/bms-clientsdk-swift-push)


This is the Push component of the Swift SDK for [IBM Bluemix Mobile Services](https://console.ng.bluemix.net/docs/mobile/index.html).


## Contents

This package contains the Push components of the Swift SDK.
* Push Registration
* Subscribing and Unsubcribing for Tags


## Requirements

* iOS 8.0+
* Xcode 7.3, 8.0 beta 4, 8.0 beta 5
* Swift 2.2 - 3.0


## Installation

The Bluemix Mobile Services Swift SDKs are available via [Cocoapods](http://cocoapods.org/) and [Carthage](https://github.com/Carthage/Carthage).


### Cocoapods
To install BMSCore using Cocoapods, add it to your Podfile:

```ruby
use_frameworks!

target 'MyApp' do
    platform :ios, '8.0'
    pod 'BMSCore'
    pod 'BMSPush'
end
```
From the Terminal, go to your project folder and install the dependencies with the following command:

```
pod install
```

####Swift 2.3

Before running the `pod install` command, make sure to use Cocoapods version [1.1.0.beta.1](https://github.com/CocoaPods/CocoaPods/releases/tag/1.1.0.beta.1).

####Swift 3.0

Before running the `pod install` command, make sure to use Cocoapods version [1.1.0.beta.1](https://github.com/CocoaPods/CocoaPods/releases/tag/1.1.0.beta.1).

For apps built with Swift 3.0, you may receive a prompt saying "Convert to Current Swift Syntax?" when opening your project in Xcode 8 (following the installation of BMSCore). Always choose the Later option.

This will installs your dependencies and creates a new Xcode workspace.
***Note:*** Ensure that you always open the new Xcode workspace, instead of the original Xcode project file:

```
   MyApp.xcworkspace
```

### Carthage
To install BMSPush using Carthage, add it to your Cartfile:

```
github "ibm-bluemix-mobile-services/bms-clientsdk-swift-push"
```

Then run the `carthage update` command. Once the build is finished, drag `BMSPush.framework`,`BMSCore.framework` and `BMSAnalyticsAPI.framework` into your Xcode project.

To complete the integration, follow the instructions [here](https://github.com/Carthage/Carthage#getting-started).

####Xcode 8

Carthage currently is not supported for BMSCore in Xcode 8 beta. Please use Cocoapods instead.

## Enabling iOS applications to receive push notifications

##### Reference the SDK in your code.

```
import BMSPush
import BMSCore
```
#### Initializing the Core SDK

```
let myBMSClient = BMSClient.sharedInstance

//Swift3

myBMSClient.initializeWithBluemixAppRoute(bluemixAppRoute: "https://example.mybluemix.net", bluemixAppGUID: "1234", bluemixRegion: "Location where your app Hosted")

// Swift 2.3 or Older

myBMSClient.initializeWithBluemixAppRoute("bluemixAppRoute", bluemixAppGUID: "APPGUID", bluemixRegion:"Location where your app Hosted")

myBMSClient.defaultRequestTimeout = 10.0 // Timput in seconds

```
***bluemixAppRoute***

Specifies the route that is assigned to the server application that you created on Bluemix.

***bluemixAppGUID***

Specifies the unique key that is assigned to the application that you created on Bluemix. This value is
case-sensitive.

***bluemixRegion***

Specifies the location where the app hosted. You can use one of three values - `BMSClient.REGION_US_SOUTH`, `BMSClient.REGION_UK` and `BMSClient.REGION_SYDNEY`.

#### Initializing the Push SDK

```
let push =  BMSPushClient.sharedInstance

//Swift 3
 push.initializeWithAppGUID(appGUID: "")

 //Swift 2.3 or Older
push.initializeWithAppGUID("appGUID")
```
***appGUID***

The Push app GUID value.

For *userId* based notifiction initialize the `BMSPush` with `clientSecret` .

```
let push =  BMSPushClient.sharedInstance

//Swift 3

push.initializeWithAppGUID(appGUID: "your push appGUID", clientSecret:"your push client secret")

//Swift2.3 or Older
push.initializeWithAppGUID("appGUID", clientSecret:"clientSecret")
```

***appGUID***

The Push app GUID value.

***clientSecret***

The Push client secret value.

#### Registering iOS applications and devices

Add this code to registering the app for push notification in APNS,

```

//swift3 
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
UIApplication.sharedApplication().registerForRemoteNotifications()

```    
After the token is received from APNS, pass the token to Push Notifications as part of the
 ***didRegisterForRemoteNotificationsWithDeviceToken*** method.

```
 func application (application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData){

   let push =  BMSPushClient.sharedInstance
   push.initializeWithAppGUID("pushAppGUID")
   push.registerWithDeviceToken(deviceToken) { (response, statusCode, error) -> Void in

        if error.isEmpty {

            print( "Response during device registration : \(response)")

            print( "status code during device registration : \(statusCode)")
        }
        else{
            print( "Error during device registration \(error) ")

            Print( "Error during device registration \n  - status code: \(statusCode) \n Error :\(error) \n")
        }
    }

}
```

For *user Id* based notification, the register method will accept one more parameter - *userId*


```
func application (application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData){

    let push =  BMSPushClient.sharedInstance
    push.initializeWithAppGUID("pushAppGUID", clientSecret:"clientSecret")
    push.registerWithDeviceToken(deviceToken, WithUserId: "your user id") { (response, statusCode, error) -> Void in

        if error.isEmpty {

            print( "Response during device registration : \(response)")

            print( "status code during device registration : \(statusCode)")
        }
        else{
            print( "Error during device registration \(error) ")

            Print( "Error during device registration \n  - status code: \(statusCode) \n Error :\(error) \n")
        }
    }

}
```

**WithUserId**

the User Id value you want to register in the push service

>**Note**: If userId is provided the client secret value must be provided.


#### Retrieve Available Tags and register for Tags

##### Retrieve Available tags

The ***retrieveAvailableTagsWithCompletionHandler*** API returns the list of available tags to which the device
can subscribe. After the device is subscribed to a particular tag, the device can receive any push notifications
that are sent for that tag.

Call the push service to get subscriptions for a tag.

Copy the following code snippets into your Swift mobile application to get a list of available tags to which the
device can subscribe.

```
push.retrieveAvailableTagsWithCompletionHandler({ (response, statusCode, error) -> Void in

    if error.isEmpty {

        print( "Response during retrieve tags : \(response)")

        print( "status code during retrieve tags : \(statusCode)")
    }
    else{
        print( "Error during retrieve tags \(error) ")

        Print( "Error during retrieve tags \n  - status code: \(statusCode) \n Error :\(error) \n")
    }
}
```
##### Subscribe to Available tags

```
push.subscribeToTags(response, completionHandler: { (response, statusCode, error) -> Void in

    if error.isEmpty {

        print( "Response during Subscribing to tags : \(response?.description)")

        print( "status code during Subscribing tags : \(statusCode)")
    }
    else {

        print( "Error during subscribing tags \(error) ")

        Print( "Error during subscribing tags \n  - status code: \(statusCode) \n Error :\(error) \n")
    }
}
```

##### Retrieve Subscribed tags

```
push.retrieveSubscriptionsWithCompletionHandler { (response, statusCode, error) -> Void in

    if error.isEmpty {

        print( "Response during retrieving subscribed tags : \(response?.description)")

        print( "status code during retrieving subscribed tags : \(statusCode)")
    }
    else {

        print( "Error during retrieving subscribed tags \(error) ")

        Print( "Error during retrieving subscribed tags \n  - status code: \(statusCode) \n Error :\(error) \n")
    }
}
```
#### unsubscribing tags

Use the following code snippets to allow your devices to get unsubscribe
from a tag.

```
push.unsubscribeFromTags(response, completionHandler: { (response, statusCode, error) -> Void in

    if error.isEmpty {

        print( "Response during unsubscribed tags : \(response?.description)")

        print( "status code during unsubscribed tags : \(statusCode)")
    }
    else {
        print( "Error during  unsubscribed tags \(error) ")

        print( "Error during unsubscribed tags \n  - status code: \(statusCode) \n Error :\(error) \n")
    }
}
```
#### Unregistering the Device from Bluemix Push Notification

Use the following code snippets to Unregister the device from Bluemix Push Notification

```
push.unregisterDevice({ (response, statusCode, error) -> Void in

    if error.isEmpty {

        print( "Response during unregistering device : \(response)")

        print( "status code during unregistering device : \(statusCode)")
    }
    else{
        print( "Error during unregistering device \(error) ")

        print( "Error during unregistering device \n  - status code: \(statusCode) \n Error :\(error) \n")
    }
}
```

###Learning More
* Visit the **[Bluemix Developers Community](https://developer.ibm.com/bluemix/)**.

* [Getting started with IBM MobileFirst Platfrom for iOS](https://www.ng.bluemix.net/docs/mobile/index.html)

###Connect with Bluemix

[Twitter](https://twitter.com/ibmbluemix) |
[YouTube](https://www.youtube.com/playlist?list=PLzpeuWUENMK2d3L5qCITo2GQEt-7r0oqm) |
[Blog](https://developer.ibm.com/bluemix/blog/) |
[Facebook](https://www.facebook.com/ibmbluemix) |
[Meetup](http://www.meetup.com/bluemix/)


=======================
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.

{'fraction_non_alphanumeric': 0.11502086230876217, 'fraction_numerical': 0.005795085767269356, 'mean_word_length': 4.037599252685661, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 30, 'lorem ipsum': 0, 'www.': 10, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4164249', 'n_tokens_mistral': 6578, 'n_tokens_neox': 6179, 'n_words': 2125}