Skip to content

Commit 51f5f9a

Browse files
authored
Update README to swift 3 syntax
1 parent 3238dd1 commit 51f5f9a

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

README.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
[<img align="left" src="logo.png" hspace="20">](#logo) Starting to integrate URL scheme in an app,
1515
why not be compliant with [x-callback-url](http://x-callback-url.com/specifications/).
1616
```swift
17-
CallbackURLKit.registerAction("play") { parameters, ... in
17+
CallbackURLKit.register(action: "play") { parameters, ... in
1818
self.player.play()
1919
}
2020
```
2121
Want to interact with one of the numerous other applications which implement already [x-callback-url](http://x-callback-url.com/apps/), you can also use this framework.
2222

2323
```swift
24-
CallbackURLKit.performAction("open", URLScheme: "googlechrome-x-callback",
24+
CallbackURLKit.perform(action: "open", urlScheme: "googlechrome-x-callback",
2525
parameters: ["url": "http://www.google.com"])
2626
```
2727

@@ -30,12 +30,12 @@ CallbackURLKit.performAction("open", URLScheme: "googlechrome-x-callback",
3030
### Perform action on other applications
3131
Anywhere in your code after imported CallbackURLKit you can call
3232
```swift
33-
try CallbackURLKit.performAction("actionName", URLScheme: "applicationName",
33+
try CallbackURLKit.perform(action: "actionName", urlScheme: "applicationName",
3434
parameters: ["key1": "value1"])
3535
```
3636
You can also use a new `Manager` or the shared instance
3737
```swift
38-
try Manager.sharedInstance.performAction("actionName", URLScheme: "application-name",
38+
try Manager.sharedInstance.perform(action: "actionName", urlScheme: "application-name",
3939
parameters: ["key1": "value1"])
4040
```
4141

@@ -47,17 +47,17 @@ In iOS 9 you must whitelist any URL schemes your app wants to query in Info.plis
4747
#### Create a client class
4848
Alternatively you can create a new `Client` object where you can define the targeted app URL scheme.
4949
```swift
50-
let client = Client(URLScheme: "application-url-scheme")
51-
try client.performAction(..)
50+
let client = Client(urlScheme: "application-url-scheme")
51+
try client.perform(action:(..)
5252
```
5353
or create a new `Client` class to add some utility methods which hide implementation details and allow to make some parameters check.
5454
```swift
5555
class GoogleChrome: Client {
5656
init() {
57-
super.init(URLScheme:"googlechrome-x-callback")
57+
super.init(urlScheme:"googlechrome-x-callback")
5858
}
59-
func openURL(url: String, ...) {
60-
self.performAction("open", parameters: ["url": url], ...)
59+
func open(url: String, ...) {
60+
self.perform(action: "open", parameters: ["url": url], ...)
6161
}
6262
}
6363
```
@@ -71,10 +71,11 @@ Callbacks allow you to receives informations or status from the targeted applica
7171
Then you can specify one of the 3 x-callbacks: success, failure and cancel
7272

7373
```swift
74-
try client.performAction("actionName",
74+
try client.performn(action: "actionName",
7575
onSuccess: { parameters in
7676
},
77-
onFailure: { error in
77+
78+
onFailure: { error in
7879
},
7980
onCancel: {
8081
}
@@ -108,11 +109,18 @@ And finally to handle incoming URLs, your application delegate should implement
108109

109110
On iOS
110111
```swift
111-
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
112-
manager.handleOpenURL(url)
112+
func application(_ application: UIApplication, open url: NSURL, sourceApplication: String?, annotation: Any) -> Bool {
113+
manager.handleOpen(url: url)
114+
return true
115+
}
116+
117+
@available(iOS 9.0, *)
118+
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
119+
manager.handleOpen(url: url)
113120
return true
114121
}
115122
```
123+
116124
On OSX if you have no other need with URL events you can let manager do all the job by calling into `applicationDidFinishLaunching`
117125
the method `Manager.instance.registerToURLEvent()`
118126

@@ -133,7 +141,7 @@ manager["myActionName"] = { parameters, success, failure, cancel in
133141
```
134142
You can also register an action on shared `Manager` instance using
135143
```swift
136-
CallbackURLKit.registerAction("myActionName") { parameters, success, failure, cancel in
144+
CallbackURLKit.register(action: "myActionName") { parameters, success, failure, cancel in
137145

138146
}
139147
```

0 commit comments

Comments
 (0)