{"id":17090835,"url":"https://github.com/phimage/callbackurlkit","last_synced_at":"2025-04-05T04:12:05.721Z","repository":{"id":3272413,"uuid":"48923701","full_name":"phimage/CallbackURLKit","owner":"phimage","description":"Implementation of x-callback-url (Inter app communication) in swift","archived":false,"fork":false,"pushed_at":"2022-04-24T09:45:04.000Z","size":151,"stargazers_count":339,"open_issues_count":2,"forks_count":61,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-29T03:07:59.105Z","etag":null,"topics":["cocoapods","communication","ios","scheme","swift","url-scheme","x-callback-url","xcode"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phimage.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"phimage","custom":"https://www.paypal.com/paypalme2/ericphimage"}},"created_at":"2016-01-02T21:00:30.000Z","updated_at":"2025-03-09T05:49:56.000Z","dependencies_parsed_at":"2022-08-06T13:16:41.277Z","dependency_job_id":null,"html_url":"https://github.com/phimage/CallbackURLKit","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phimage%2FCallbackURLKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phimage%2FCallbackURLKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phimage%2FCallbackURLKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phimage%2FCallbackURLKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phimage","download_url":"https://codeload.github.com/phimage/CallbackURLKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247284951,"owners_count":20913704,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cocoapods","communication","ios","scheme","swift","url-scheme","x-callback-url","xcode"],"created_at":"2024-10-14T13:56:52.449Z","updated_at":"2025-04-05T04:12:05.702Z","avatar_url":"https://github.com/phimage.png","language":"Swift","readme":"# CallbackURLKit - Inter app communication\n\n[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat\n            )](http://mit-license.org)\n[![Platform](http://img.shields.io/badge/platform-ios_osx_tvos-lightgrey.svg?style=flat\n             )](https://developer.apple.com/resources/)\n[![Language](http://img.shields.io/badge/language-swift-orange.svg?style=flat\n             )](https://developer.apple.com/swift)\n[![Issues](https://img.shields.io/github/issues/phimage/CallbackURLKit.svg?style=flat\n           )](https://github.com/phimage/CallbackURLKit/issues)\n[![Cocoapod](http://img.shields.io/cocoapods/v/CallbackURLKit.svg?style=flat)](http://cocoadocs.org/docsets/CallbackURLKit/)\n\n\u003ca href=\"https://www.patreon.com/phimage\"\u003e\n\u003cimg src=\"https://c5.patreon.com/external/logo/become_a_patron_button.png\" alt=\"Become a Patron!\" height=\"35\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://paypal.me/ericphimage\"\u003e\n\u003cimg src=\"https://buymecoffee.intm.org/img/button-paypal-white.png\" alt=\"Buy me a coffee\" height=\"35\"\u003e\n\u003c/a\u003e\n\n[\u003cimg align=\"left\" src=\"logo.png\" hspace=\"20\"\u003e](#logo) Starting to integrate URL scheme in an app,\nwhy not be compliant with [x-callback-url](http://x-callback-url.com/specifications/).\n```swift\nCallbackURLKit.register(action: \"play\") { parameters, ... in\n  self.player.play()\n}\n```\nWant 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.\n\n```swift\nCallbackURLKit.perform(action: \"open\", urlScheme: \"googlechrome-x-callback\",\n                             parameters: [\"url\": \"http://www.google.com\"])\n```\n\n## Usage\n\n### Perform action on other applications\nAnywhere in your code after imported CallbackURLKit you can call\n```swift\ntry CallbackURLKit.perform(action: \"actionName\", urlScheme: \"applicationName\",\n    parameters: [\"key1\": \"value1\"])\n```\nYou can also use a new `Manager` or the shared instance\n```swift\ntry Manager.shared.perform(action: \"actionName\", urlScheme: \"application-name\",\n    parameters: [\"key1\": \"value1\"])\n```\n\n#### Declare targeted applications URL schemes in iOS9\nYou must whitelist any URL schemes your app wants to query in Info.plist under the *LSApplicationQueriesSchemes* key (an array of strings)\n\n![xcode-white-list](http://useyourloaf.com/assets/images/2015/2015-09-06-001.png)\n\n#### Create a client class\nAlternatively you can create a new `Client` object where you can define the targeted app URL scheme.\n```swift\nlet client = Client(urlScheme: \"application-url-scheme\")\ntry client.perform(action:(..)\n```\nor create a new `Client` class to add some utility methods which hide implementation details and allow to make some parameters check.\n```swift\nclass GoogleChrome: Client {\n  init() {\n    super.init(urlScheme:\"googlechrome-x-callback\")\n  }\n  func open(url: String, ...) {\n    self.perform(action: \"open\", parameters: [\"url\": url], ...)\n  }\n}\n```\nsee full sample into [Clients](/Clients) directory. *(You can PR to add new `Client` classes)*\n\nYou can check that an application respond to the URL scheme using `client.appInstalled`\n\n#### Use callback closure\nCallbacks allow you to receive data from the target applications, *but before doing this you need to [add x-callback-url support to your app](#add-x-callback-url-support-to-your-app).*\n\nThen you can specify one of the 3 x-callbacks: success, failure and cancel.\n\n```swift\ntry client.perform(action: \"actionName\",\n    onSuccess: { parameters in\n    },\n\nonFailure: { error in\n    },\n    onCancel: {\n    }\n)\n```\n\n### Add x-callback-url support to your app ###\n\n#### Register your URL scheme\nApps 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.\n![xcode](https://raw.githubusercontent.com/OAuthSwift/OAuthSwift/master/Assets/URLSchemes.png)\n\nOr register your URL Scheme directly into Info.plist file:\n- Add URL Types, then within Item 0\n- Set Document Role to Editor.\n- URL Identifier to your app bundle ID.\n- Create a URL Schemes field and set Item 0 to the URL Scheme you want to use.\n\nApple documentation: [Using URL Schemes to Communicate with Apps](https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html#//apple_ref/doc/uid/TP40007072-CH6-SW1).\n\n#### Setup framework with URL scheme\nThen you must set the scheme to this framework manager\n ```swift\n let manager =  Manager.shared\n manager.callbackURLScheme = \"my-application-scheme\"\n // or get the first from Info.plist using utility method\n manager.callbackURLScheme = Manager.urlSchemes?.first\n ```\n#### Handle incoming URLs\nAnd finally to handle incoming URLs, your application delegate should implement the following methods below.\n\nOn iOS\n```swift\nfunc application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -\u003e Bool {\n    manager.handleOpen(url: url)\n    return true\n}\n```\n\nOn OSX if you have no other need with URL events you can let manager do all the job by calling into `applicationDidFinishLaunching`\nthe method `Manager.instance.registerToURLEvent()`\n\n#### Add new action\nThe client application will interact with your application using the following URL Structure.\n\n`[url-scheme]://x-callback-url/[action]?[x-callback parameters]\u0026[action parameters]`\n\nAn action is defined by its name (the url path), and optional action `parameters`.\n\n```swift\nmanager[\"myActionName\"] = { parameters, success, failure, cancel in\n  // action code, using or not the parameters\n  ...\n  // notify the client app with one of the callback\n  success(nil) // or failure(exception)\n}\n```\nYou can also register an action on shared `Manager` instance using\n```swift\nCallbackURLKit.register(action: \"myActionName\") { parameters, success, failure, cancel in\n\n}\n```\n\n## Installation\n\n## Using CocoaPods ##\n[CocoaPods](https://cocoapods.org/) is a centralized dependency manager for\nObjective-C and Swift. Go [here](https://guides.cocoapods.org/using/index.html)\nto learn more.\n\n1. Add the project to your [Podfile](https://guides.cocoapods.org/using/the-podfile.html).\n\n    ```ruby\n    use_frameworks!\n\n    pod 'CallbackURLKit'\n    ```\n\n2. Run `pod install` and open the `.xcworkspace` file to launch Xcode.\n\n### Clients\nTo get an already implemented [Clients](/Clients) use one of the subspec\n```ruby\npod 'CallbackURLKit/GoogleChrome'\npod 'CallbackURLKit/Ulysses' // https://ulyssesapp.com\n```\n\n## Links\n- [http://x-callback-url.com/](http://x-callback-url.com/)\n- [https://onetapless.com/library](https://onetapless.com/library)\n- [http://handleopenurl.com/](http://handleopenurl.com/)\n","funding_links":["https://github.com/sponsors/phimage","https://www.paypal.com/paypalme2/ericphimage","https://www.patreon.com/phimage","https://paypal.me/ericphimage"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphimage%2Fcallbackurlkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphimage%2Fcallbackurlkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphimage%2Fcallbackurlkit/lists"}