Detecting my iOS application as a web browser

I am creating a browser application. I want iOS to detect it as a browser. I tried adding http to the urls, but in vain.

I tried this answer .

+7
browser ios xcode swift
source share
3 answers

On iOS, the OS does not track which applications are browsers, and as for the system, the user must use Safari for everything. Therefore, the API does not look like a question related to macOS related to you.

However, if you want your application to appear in the Open pop-up window, you can set your application as capable of opening certain types of documents . There are many system-declared document types , but you can highlight network-related ones such as public.html ( kUTTypeHTML ).

Unfortunately, I'm sure iOS doesn't allow apps to declare support for opening simple http URLs, only custom URL patterns, but you can still declare support for certain file types, such as HTML, just in case the user tries open it up. Here is an example:

First, you need to tell Xcode which documents you support, you do this by choosing your purpose, sending information and adding document types:

Adding public.html to document types

Then, at any time when your application is prompted to open the .webarchive file, this document describes how you should open it. Basically, since you don’t own the file type, you can just look inside the parameter dictionary in application:didFinishLaunchingWithOptions: or application:willFinishLaunchingWithOptions .

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { if let url = launchOptions?[UIApplicationLaunchOptionsKey.url] as? URL { // This code would probably exist in one of your controllers let request = URLRequest(url: url) webview.load(request) } return true } 

Thus, in reality, AppDelegate will most likely delegate this to another part of your application, simply by passing it the URL .

But then again, the user probably won’t be able to just go to Safari and just share the web page with your application. Your application will most likely only show up when the user actually clicks share on the actual html file, but this is probably the closest thing that iOS offers for what you want.

+1
source share

Not possible to define anywhere in the application that another application displays your application as a browser, but if you want to add URLs from another application to your application, you can create a sharing extension for your application. This will allow other applications to share URLs with your application. When a user selects a URL and shares it, they will see your application. You can customize the viewing of the sharing view for your class with NSExtensionMainStoryboard . Learn more about this from the Apple Developer website.

However, this will not open your application when the user selects a URL. the user will have to close another application and open the application to view the shared URL in your application. for this you can display the correct message from the SharingViewController class.

When the user will exchange URLs with your application, the delegation method didSelectPost () in your SharingViewController will be called, you can get a common URL from this method and use it in your application.

  override func didSelectPost() { if let item = extensionContext?.inputItems.first as? NSExtensionItem { if let itemProvider = item.attachments?.first as? NSItemProvider { if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeURL) { itemProvider.loadItemForTypeIdentifier(kUTTypeURL, options: nil, completionHandler: { (url, error) -> Void in if let shareURL = url as? NSURL { var defaults = NSUserDefaults(suiteName: "group.com.yourapp.extension") defaults?.setObject(url.absoluteString(), forKey: "sharedURL") defaults?.synchronize() } self.extensionContext?.completeRequestReturningItems([], completionHandler:nil) }) } } } } 

You can get the value store in NSUserDefalts with the costume name in your application and display the URL from it.

  var defaults = NSUserDefaults(suiteName: "group.com.yourapp.extension") defaults?.synchronize() // Check for null value before setting if let restoredValue = defaults!.stringForKey("sharedURL") { //create url with sctring and use it as per your requirement } else { // ("Cannot find value") } 
+1
source share

This is not possible, http is a reserved URL scheme, see Using URL schemes to communicate with applications

Apple provides native support for the http, mailto, tel, and sms URLs. schemes among others. It also supports http-based URLs targeting Maps, YouTube, and iPod apps. Handlers for these schemes are fixed and cannot be changed. If your URL type includes a scheme that is identical to the one defined by Apple, the Apple application provided in place of your application.

What you can do is use Universal Links with your application and use your application (if installed) as a browser for your website. You cannot achieve this for all URLs.

+1
source share

All Articles