Skip to content

Utilizing SafariViewController in iOS 9 and sharing data back to native app via custom URL scheme (Objective-C)

License

Notifications You must be signed in to change notification settings

freedomofkeima/ios-safariview-example

Repository files navigation

ios-safariview-example

This repository contains an example of SFSafariViewController for iOS 9 and up in Objective-C. This repository is mainly created because there is no proper documentation on how to pass data between Safari and your native apps in Objective-C.

By using this example, you will learn how to:

  • Open your web content via SFSafariViewController directly
  • Implement a callback when "Done" button is pressed via safariViewControllerDidFinish (normal way)
  • Invoke a callback via custom URL scheme (e.g.: redirection) & NSNotificationCenter
  • Allow backwards compatibility with iOS 8 and below (of course, without this functionality)

As a reference, this repository is inspired from mackuba/SafariAutoLoginTest. In addition to seamless auto-login, one of the other motivation in using this technique is to support certificate sharing between native apps which are not signed under same publishers.

Screenshot

Allow custom URL scheme invocations

You need to configure the value of LSApplicationQueriesSchemes and URL types in your Info.plist. In this example, it's already provided so you don't need to change anything.

Allow backwards compatibility

In order to use lower deployment target (e.g.: iOS 8.1) safely, you need to change the binary which is linked from Required to Optional.

How to test (callback via URL scheme)

  • Clone this project

  • In your website, use the following example code to redirect your client to freedomofkeima://?ThisIsResponseSample

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Refresh" content="3; URL='freedomofkeima://?ThisIsResponseSample'">
    </head>
    <body>
    </body>
</html>
  • Add your url_endpoint here

  • Open this project in Xcode and run it

License

MIT License.

Last Updated: September 1, 2016

About

Utilizing SafariViewController in iOS 9 and sharing data back to native app via custom URL scheme (Objective-C)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published