Is it possible for native iOS application to interact with Safari browser? - iphone

I would like to enable interaction between a native iOS application and the Safari browser such that tapping a right click on an image on a webpage provides an option in the context menu to send the image to another custom written native iOS application for further processing and/or storage.
However, according to this article from Safari Developer Library, “Safari extensions are not currently supported on iOS”.
Is there any other alternative to achieve the above functionality?

You have multiple choices here:
You could register in your application's Info.plist file that your app known how to handle certain type of documents (see here in Apple's doc). This way when your iPhone encounters this document type, iOS will propose the user to open this document in your app; for example if you register for the PDF type and you then tap on a PDF document as an attachment in a mail, you app will be listed in the proposed menu and will then be opened with the document as a parameter.
But it seems that even if this works perfectly for any type like DOC, PDF, or even custom types, it does not work for images, which seems to be handled in a separate way by iOS :(
A simpler way would be to register, still in your application's Info.plist, any custom URL schemes. See here and below in the Apple's doc. For example when, anywhere in your iPhone (either in your own app, or in another third-party app, including Safari), it encounters URLs like "myapp://xxx/yyy/zzz", it opens your app, passing this URL as an argument. You can then do whatever you want with this URL.
The solution then is to add some code in your web page so that when the image is tapped, you ask Safari to open the URL "myimageditor://edit?url=http://www.url.of/your/image.jpg". If you registered for the "myimageeditor://" URL scheme, you app will then open with the URL in the parameters, and you then will be able to retrieve the image using the embed URL.

I think it is possible only for jailbroken devices.

Related

Find all registered mime-types / url scheme protocols (intent filters) on iOS ( iPhone / iPad / iPod )

I'm a mobile web developer, and I'd like to test a few iOS devices to see what mime-types and url schemes the average iOS device can accept.
On Android I'm able to install an app called PackageExplorer that lists all the "intent filters" for all the apks and lists what file mime-types (image/png, text/html, text/x-vcard) and url schemes (like geo:, tel:, sms:, mailto:, http://youtube.com) the app handles.
It would be really nice if I could tell what schemes and mime-types are supported/registered from the server or browser side on my mobile webpages, but if that's not possible, I'm looking for a display or an app in iOS to view all the registered file mime-types and url scheme protocols that the device currently supports with all it's installed apps.
How do i find all the registered scheme/mime intent filters on an iOS device?
UPDATE: I don't know if it's complete, but I found an official list of url schemes sported in mobile safari: https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html (still looking for mime-types etc.)
This information is not available per se. You can however build an app that tries out content of varying types with different content-types and look whether this displays nicely or doesn't.
We've had one situation where the content type for Powerpoint was not registered on the web server and thus UIWebView was unable to display it. It will in these cases respond with a specific error code instead of didFinishLoading. When it was fixed on the server it started working in the app as well.
A slight complication there is that the test files would have to served by a web server because fileURL-based documents don't have a content type. There webkit inside UIWebView auto-detects the file type.
Though in all likelihood this information will prove to be useless to you for a simple reason: apps can always register to open certain file types on the device. The document interaction controller can be used to hand off the opening of the content in this other app. And since this extends the number of viewable document types infinitely you can never how to have a complete list.
So what you really would want is a list of these types of files that UIWebView can display, but you have this list already, you have quoted Apple's URL in your question.

Choosing what Iphone app must open one url schema

I'm able to open a url scheme with my apps. However i can have more that one app with the same
url scheme registered so i would like let user choose the default app for the scheme.
I need to use the same scheme for all my apps. Now by default iphone uses the last app installed that can open the schema.
Have you same idea to solve my problem?
Do you know if is possible inside an app choose itself as default to open a url scheme?
I can't find the possibility to do this in generale setting of Iphone.
Thanks you
It is not supported. Here is a note from Apple documentation.
If your URL type includes a scheme
that is identical to one defined by
Apple, the Apple-provided application
is launched instead of your
application. If multiple third-party
applications register to handle the
same URL scheme, it is undefined as to
which of the applications is picked to
handle URLs of that type.
Implementing Standard Application Behaviors
A possible solution would be to have your apps connect to the your server to get a list of your apps and their supported URL schemes. You can present that list to the user and the user can select the default app.

Can you open apps within other apps, with no URL scheme?

Is it possible to open another app, like Camera, from a third-party app? I know there are URL schemes - http://wiki.akosma.com/IPhone_URL_Schemes - but I just want to open an app, not send any data to the app.
Unfortunately, no. Launch Services is private API on the iPhone. You application can launch another app only through trying to open a URL registered by that app or a file document the app understands. However, as far as I know, your app has no control over or knowledge about which app exactly will handle the URL or the file.
One way to fire up the camera from within your app, of course, is the UIImagePickerController class.
http://developer.apple.com/iphone/library/documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html
It's not quite what you're asking, but it might be as close as you're going to get.

Launching a native application from a link of website on iPhone

I have a query regarding launching a native application from a link of website on iPhone.
I will explain.
Generally a web based application is used to work online without using any feature of iPhone device (such as GPS, Camera, Accelerometer etc.)
I have a iPhone specific website which performs many tasks online.
Now while keeping all the functionality same, I want to add a feature of taking a picture from iPhone in-built camera.
i.e. when user clicks a button on website "Take Picture", my native application should be launched, which will take a picture and do specific tasks..
How to capture a event of button click which is performed on website?
Should I use UIWebView or Safari?
I know that using URL Scheme we can launch Safari from native application.
But how to achieve the opposite as explained above?
All other functionality works great on website, so I don't want to convert the whole website into native application.
(Otherwise I will have to deal with web services). Only this functionality needs to be added.
Register a URL Handler, then have a link on your site to myapphandle://some.parameters.here/
A la: http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html

WebKit on th iPhone: is it possible to copy text to the clipboad with JavaScript

The iPhone 3.0 software added copy/paste, and native application can programmatically copy content to the clipboard. Is it possible to do the same, i.e. copy text to the clipboard, from JavaScript code running inside Safari on the iPhone?
On the desktop, copy/paste in websites typically seems to use an embedded Flash gizmo; obviously on the iPhone that's neither possible nor desirable. You might try one of the webView:shouldStartLoadWithRequest:navigationType: techniques discussed in Nick Dalton's presentation here to pull information out of your web view, then call an appropriate UIPasteboard method.
edit: My apologies—didn't read the post correctly. If it's in the main Safari app as opposed to one whose UIWebView you control, I don't think there is a way to force a copy. Glyphboard (site only works from within non-desktop Safari) is an example of a site that would probably be making use of this functionality if it existed.