测试已测试 | ✓ |
语言语言 | SwiftSwift |
许可证 | Apache 2 |
发布最新发布 | 2017年1月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✓ |
由 Alexey Khokhlov 维护。
用于发送 Apple 推送通知的简单框架。
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>)
需要 Protocol Buffers 3.0 和 protobuf-swift。
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 {
}
编辑 ./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;
}
编译新对象
protoc PushService.proto --swift_out="../"
标志中使用的鸟 - 以及云 - 分别借用自原始的 Swift 和 APNs 标志,*版权所有 Apple Inc.*。
标志中使用的字体来自 San Francisco 字体系列。