Latest0.1.0
Homepagehttps://github.com/Matzo/SwiftWatchConnectivity
LicenseMIT
Platformsios 9.3, watchos 4.0
Authors

CI Status
Version
License
Platform
iOS
watchOS
Swift

SwiftWatchConnectivity is a WatchConnectivity simple wrapper.

Features

  • Queueing requested and received task until all available
  • Support all transer between iOS and watchOS

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Prepare

  • for iOS code
    
    // 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
}
}


- for watchOS code
``` swift
// 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 data

// 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. To install
it, simply add the following line to your Podfile:

pod 'SwiftWatchConnectivity'

Author

[email protected],

License

SwiftWatchConnectivity is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "SwiftWatchConnectivity",
    "version": "0.1.0",
    "summary": "Simple WatchConnectivity wrapper.",
    "description": "SwiftWatchConnectivity is a WatchConnectivity simple wrapper.n- Queueing requested and received task until all availablen- Support all transer between iOS and watchOS",
    "homepage": "https://github.com/Matzo/SwiftWatchConnectivity",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "[email protected]": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Matzo/SwiftWatchConnectivity.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "9.3",
        "watchos": "4.0"
    },
    "source_files": "SwiftWatchConnectivity/Classes/**/*",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This