SwiftWatchConnectivity 0.1.0

SwiftWatchConnectivity 0.1.0

测试已测试
语言语言 SwiftSwift
许可 MIT
发布最新发布2017年10月
SwiftSwift 版本4.0
SPM支持 SPM

Matzo 维护。









SwiftWatchConnectivity 是一个 WatchConnectivity 简单包装器。

功能

  • 排队请求和接收的任务,直到所有可用
  • 支持在 iOS 和 watchOS 之间的所有传输

示例

要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install

准备

  • 为 iOS 代码
// ViewController.swift
override func viewDidLoad() {
    super.viewDidLoad()
    SwiftWatchConnectivity.shared.delegate = self
}

func connectivity(_ swiftWatchConnectivity: SwiftWatchConnectivity, updatedWithTask task: SwiftWatchConnectivity.Task) {
    switch task {
    case .sendMessage(let message):
        // message is dictionaly that was sent by opponent OS
    default:
        break
    }
}
  • 为 watchOS 代码
// InterfaceController.swift
override func awake(withContext context: Any?) {
    super.awake(withContext: context)

    // Configure interface objects here.
    SwiftWatchConnectivity.shared.delegate = self
}

func connectivity(_ swiftWatchConnectivity: SwiftWatchConnectivity, updatedWithTask task: SwiftWatchConnectivity.Task) {
    switch task {
    case .sendMessage(let message):
        // message is dictionaly that was sent by opponent OS
    default:
        break
    }
}

// ExtensionDelegate.swift
func handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) {
    SwiftWatchConnectivity.shared.handle(backgroundTasks)
        :
}

发送数据

// send dictionary immediately
SwiftWatchConnectivity.shared.sendMesssage(message: ["msg": NSDate()])
// send dictionary in foreground or background
SwiftWatchConnectivity.shared.transferUserInfo(userInfo: [
    "string": "hello",
    "bool": false,
    "array": [1,2,3]
])
// send file with metadata
let fileURL = Bundle.main.url(forResource: "dog", withExtension: "jpg")!
SwiftWatchConnectivity.shared.transferFile(fileURL: fileURL, metadata: ["Level": 8])
``

## Requirements
- iOS 9.3
- watchOS 4.0
- Swift 4.0

## Installation

SwiftWatchConnectivity is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:

```ruby
pod 'SwiftWatchConnectivity'

作者

[email protected],

许可

SwiftWatchConnectivity 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。