All Projects → phimage → Callbackurlkit

phimage / Callbackurlkit

Licence: mit
Implementation of x-callback-url (Inter app communication) in swift

Programming Languages

swift
15916 projects
scheme
763 projects

Projects that are alternatives of or similar to Callbackurlkit

Dtpagercontroller
A fully customizable container view controller to display a set of ViewControllers in a horizontal scroll view. Written in Swift.
Stars: ✭ 240 (-19.73%)
Mutual labels:  xcode, cocoapods
Roundcode
Custom rounded QR code with lots of customization.
Stars: ✭ 267 (-10.7%)
Mutual labels:  xcode, cocoapods
Autoarchive
一个基于Jenkins的iOS/Android自动构建系统,它实现了最大程度的自动化,让你的iOS自动打包,Android自动打包流程变得更加高效。此项目包含了各种实现细节的讲解说明,你能够使用它解决大多数跟客户端构建/分发相关的问题,并将这种能力进行开放,提高研发效率。
Stars: ✭ 248 (-17.06%)
Mutual labels:  xcode, cocoapods
Shsearchbar
The search bar that doesn't suck.
Stars: ✭ 206 (-31.1%)
Mutual labels:  xcode, cocoapods
Imageloaderswift
A lightweight and fast image loader for iOS written in Swift.
Stars: ✭ 290 (-3.01%)
Mutual labels:  xcode, cocoapods
Dtphotoviewercontroller
A fully customizable photo viewer ViewController to display single photo or collection of photos, inspired by Facebook photo viewer.
Stars: ✭ 212 (-29.1%)
Mutual labels:  xcode, cocoapods
Colorizeswift
Terminal string styling for Swift.
Stars: ✭ 253 (-15.38%)
Mutual labels:  xcode, cocoapods
Cdmarkdownkit
An extensive Swift framework providing simple and customizable markdown parsing.
Stars: ✭ 158 (-47.16%)
Mutual labels:  xcode, cocoapods
Netfox
A lightweight, one line setup, iOS / OSX network debugging library! 🦊
Stars: ✭ 3,188 (+966.22%)
Mutual labels:  xcode, cocoapods
Containercontroller
UI Component. This is a copy swipe-panel from app: Apple Maps, Stocks. Swift version
Stars: ✭ 273 (-8.7%)
Mutual labels:  xcode, cocoapods
Countrypicker
A simple, customizable Country picker for picking country or dialing code. 🇮🇳 🇯🇵 🇰🇷 🇩🇪 🇨🇳 🇺🇸 🇫🇷 🇪🇸 🇮🇹 🇷🇺 🇬🇧
Stars: ✭ 174 (-41.81%)
Mutual labels:  xcode, cocoapods
Audioindicatorbars
AIB indicates for your app users which audio is playing. Just like the Podcasts app.
Stars: ✭ 279 (-6.69%)
Mutual labels:  xcode, cocoapods
Irldocumentscanner
A drop-in Objective-C ViewController that will Automatically scan a document for you you.
Stars: ✭ 172 (-42.47%)
Mutual labels:  xcode, cocoapods
Sbtuitesttunnel
Enable network mocks and more in UI Tests
Stars: ✭ 215 (-28.09%)
Mutual labels:  xcode, cocoapods
Tiercel
简单易用、功能丰富的纯 Swift 下载框架
Stars: ✭ 2,241 (+649.5%)
Mutual labels:  xcode, cocoapods
Localize
Localize is a framework writed in swift to localize your projects easier improves i18n, including storyboards and strings.
Stars: ✭ 253 (-15.38%)
Mutual labels:  xcode, cocoapods
Swiftcolorgen
A tool that generate code for Swift projects, designed to improve the maintainability of UIColors
Stars: ✭ 152 (-49.16%)
Mutual labels:  xcode, cocoapods
Accordionswift
The best way of implement an accordion menu using an UITableView in Swift
Stars: ✭ 156 (-47.83%)
Mutual labels:  xcode, cocoapods
Xcode One Dark
Atom One Dark theme for Xcode
Stars: ✭ 273 (-8.7%)
Mutual labels:  xcode, cocoapods
Fapaginationlayout
Collection view pagination layout
Stars: ✭ 276 (-7.69%)
Mutual labels:  xcode, cocoapods

CallbackURLKit - Inter app communication

License Platform Language Issues Cocoapod

Become a Patron! Buy me a coffee

Starting to integrate URL scheme in an app, why not be compliant with x-callback-url.

CallbackURLKit.register(action: "play") { parameters, ... in
  self.player.play()
}

Want to interact with one of the numerous other applications which implement already x-callback-url, you can also use this framework.

CallbackURLKit.perform(action: "open", urlScheme: "googlechrome-x-callback",
                             parameters: ["url": "http://www.google.com"])

Usage

Perform action on other applications

Anywhere in your code after imported CallbackURLKit you can call

try CallbackURLKit.perform(action: "actionName", urlScheme: "applicationName",
    parameters: ["key1": "value1"])

You can also use a new Manager or the shared instance

try Manager.shared.perform(action: "actionName", urlScheme: "application-name",
    parameters: ["key1": "value1"])

Declare targeted applications URL schemes in iOS9

You must whitelist any URL schemes your app wants to query in Info.plist under the LSApplicationQueriesSchemes key (an array of strings)

xcode-white-list

Create a client class

Alternatively you can create a new Client object where you can define the targeted app URL scheme.

let client = Client(urlScheme: "application-url-scheme")
try client.perform(action:(..)

or create a new Client class to add some utility methods which hide implementation details and allow to make some parameters check.

class GoogleChrome: Client {
  init() {
    super.init(urlScheme:"googlechrome-x-callback")
  }
  func open(url: String, ...) {
    self.perform(action: "open", parameters: ["url": url], ...)
  }
}

see full sample into Clients directory. (You can PR to add new Client classes)

You can check that an application respond to the URL scheme using client.appInstalled

Use callback closure

Callbacks allow you to receive data from the target applications, but before doing this you need to add x-callback-url support to your app.

Then you can specify one of the 3 x-callbacks: success, failure and cancel.

try client.perform(action: "actionName",
    onSuccess: { parameters in
    },

onFailure: { error in
    },
    onCancel: {
    }
)

Add x-callback-url support to your app

Register your URL scheme

Apps can declare any custom URL schemes they support. Use the URL Types section of the Info tab to specify the custom URL schemes that your app handles. xcode

Or register your URL Scheme directly into Info.plist file:

  • Add URL Types, then within Item 0
  • Set Document Role to Editor.
  • URL Identifier to your app bundle ID.
  • Create a URL Schemes field and set Item 0 to the URL Scheme you want to use.

Apple documentation: Using URL Schemes to Communicate with Apps.

Setup framework with URL scheme

Then you must set the scheme to this framework manager

let manager =  Manager.shared
manager.callbackURLScheme = "my-application-scheme"
// or get the first from Info.plist using utility method
manager.callbackURLScheme = Manager.urlSchemes?.first

Handle incoming URLs

And finally to handle incoming URLs, your application delegate should implement the following methods below.

On iOS

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    manager.handleOpen(url: url)
    return true
}

On OSX if you have no other need with URL events you can let manager do all the job by calling into applicationDidFinishLaunching the method Manager.instance.registerToURLEvent()

Add new action

The client application will interact with your application using the following URL Structure.

[url-scheme]://x-callback-url/[action]?[x-callback parameters]&[action parameters]

An action is defined by its name (the url path), and optional action parameters.

manager["myActionName"] = { parameters, success, failure, cancel in
  // action code, using or not the parameters
  ...
  // notify the client app with one of the callback
  success(nil) // or failure(exception)
}

You can also register an action on shared Manager instance using

CallbackURLKit.register(action: "myActionName") { parameters, success, failure, cancel in

}

Installation

Using CocoaPods

CocoaPods is a centralized dependency manager for Objective-C and Swift. Go here to learn more.

  1. Add the project to your Podfile.

    use_frameworks!
    
    pod 'CallbackURLKit'
    
  2. Run pod install and open the .xcworkspace file to launch Xcode.

Clients

To get an already implemented Clients use one of the subspec

pod 'CallbackURLKit/GoogleChrome'
pod 'CallbackURLKit/Ulysses' // https://ulyssesapp.com

Links

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].