Latest 1.2.2
Homepage https://github.com/alexeyxo/swift-apns
License Apache License, Version 2.0 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.
Copyright 2008 Google Inc.
Platforms ios 8.0, osx 10.10, requires ARC
Dependencies ProtocolBuffers-Swift
Frameworks Foundation, Security
Authors


Logo

Simple framework for sending Apple Push Notifications.

Carthage compatible

Version

Platform

Table of Contents

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate swift-apns into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'APNS', '~> 1.0'
end

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew install carthage

To integrate swift-apns into your Xcode project using Carthage, specify it in your Cartfile:

github "alexeyxo/swift-apns"

Run carthage update to build the framework and drag the built .framework file into your Xcode project.

Usage

Simple Example

let aps = ["sound":"default", "alert":"testPush()"]
let payload = ["aps":aps]
_ = try! APNSNetwork().sendPush(topic: "com.asdasd.asdasdas", priority: 10, payload: payload, deviceToken: "3dd55a59056441ab275b8b679458388cae76be3a9a02a00234388e50fe91f2fe", certificatePath: Bundle(for:UnitTest.self).pathForResource("push", ofType: "p12")!, passphrase: "123456", sandbox: true, responseBlock: { (response) in
        XCTAssertTrue(response.serviceStatus.0 == 200)
        self.expectation.fulfill()
    }, networkError: { (error) in

})

        let aps = ["sound":"default", "alert":"testPush()"]
        let payload = ["aps":aps]
        let str = Bundle(for:UnitTest.self).pathForResource("cert", ofType: "p12")!
        var mess = ApplePushMessage(topic: "com.tests.asdasdasd",
                             priority: 10,
                             payload: payload,
                             deviceToken: "3dd55a59056441ab275b8b679458388cae76be3a9a02a00234388e50fe91f2fe",
                             certificatePath:str,
                             passphrase: "123456",
                             sandbox: true,
                             responseBlock:nil,
                             networkError:nil, session: nil)

        mess.responseBlock = { response in
        }

        mess.networkError = { err in
            if (err != nil) {

            }
        }
        _ = try! mess.send() // OR try! mess.send(session:<URLSession>) 

Using with "Protocol Buffers"

Required Protocol Buffers 3.0 and protobuf-swift.

Simple Example

let providerData = Apple.Apns.ProviderData.Builder()
providerData.bundle = "com.aasdad.asdasdsdfa"
providerData.serviceIdentity = Apple.Apns.ProviderData.Identity.Development
providerData.priority = 10
providerData.certificatePath = NSBundle(forClass:UnitTest.self).pathForResource("push", ofType: "p12")!
providerData.certificatePassphrase = "123456"
providerData.token = "3dd55a59056441ab275b8b679458388cae76be3a9a02a00234388e50fe91f2fe"

let aps = Apple.Apns.Push.Aps.Builder()
aps.badge = 1
aps.contentAvailable = 1
aps.sound = "default"
aps.alert = "testSendProtobuf()"
do {
    let payload = try Apple.Apns.Push.Builder().setAps(aps.build()).build()
    providerData.payload = payload
    try APNSNetwork().sendPush(providerData.build(), responseBlock: { (response) -> () in
        print(response)
    })
} catch {

}

Sending Custom Objects

  1. Edit ./Source/ProtoSource/PushService.proto:

    ...
    message Push {
      message Aps {
          string alert = 1;
          string sound = 2;
          int32 badge = 3;
          int32 content_available = 4;
          string category = 5;
      }
    
      message ExampleCustomObject {
          string objectId = 1;
      }
    
    Aps aps = 1;
      ExampleCustomObject customObject = 2;
    }
  2. Compile new object:
    protoc PushService.proto --swift_out="../"

Credits

  • The bird used in the logo – as well as the cloud – are borrowed respectively
    from the original Swift and APNs logos which have
    *All Rights Reserved to Apple Inc.

  • The font used in logo comes from the San Francisco family.

Latest podspec

{
    "name": "APNS",
    "version": "1.2.2",
    "summary": "Swift Framework for sending Apple Push Notification over HTTP/2 API",
    "homepage": "https://github.com/alexeyxo/swift-apns",
    "license": {
        "type": "Apache License, Version 2.0",
        "text": "    Licensed under the Apache License, Version 2.0 (the "License");n    you may not use this file except in compliance with the License.n    You may obtain a copy of the License atn    http://www.apache.org/licenses/LICENSE-2.0n    Unless required by applicable law or agreed to in writing, softwaren    distributed under the License is distributed on an "AS IS" BASIS,n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.n    See the License for the specific language governing permissions andn    limitations under the License.n    Copyright 2008 Google Inc.n"
    },
    "documentation_url": "https://github.com/alexeyxo/swift-apns",
    "authors": {
        "Alexey Khokhlov": "[email protected]"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.10"
    },
    "module_name": "APNS",
    "source": {
        "git": "https://github.com/alexeyxo/swift-apns.git",
        "tag": "1.2.2"
    },
    "source_files": "Source/*.{swift}",
    "requires_arc": true,
    "frameworks": [
        "Foundation",
        "Security"
    ],
    "dependencies": {
        "ProtocolBuffers-Swift": []
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This