How to fire an UILongPressGestureRecognizer on a position programmatically - iphone

I need to send an UILongPressGestureRecognizer without user interaction on an specific position of an UIWebView. The proyect I'm working on is intended to be uploaded to the AppStore, so the given solution must be "legal".
Thanks.

Have the click on the webpage send a URL to the application when the conditions are met on the webpage. Do a google search on URL schemes (there's quite a few examples) and set up a handler in your app. Use your webpage html/javascript code to detect the long press, and when it happens send the URL scheme. For example, just like you send a "mailto:" url to send an signal to your email app, you use a "myFoobarapp:" url to trigger signals to your app. The application detects the URL scheme and does what you want. Using URL schemes is the approved method of communicating from a web page to your app. Make sure you look at the existing url schemes so the one you pick (i.e., myFoobarapp) isn't already taken.

Related

How to implement my android algorithm on iOS?

I have an android app working this way:
User read QR-code with my specific URL
If the app installed it intercepts this URL and handles it somehow.
If app not installed standard browser opens this URL and it leads to Google play on app page.
When user install and run app first time it read browser's history and look for my URL.
If app found URL in browser's history then it handles this URL again.
Is it possible to implement this behavior on iPhone/iPad?
I suppose key features here are to read browser history and to intercept http URL's.
If this is impossible how would you implement this thing on iOS?
Thanks in advance for your help.
You can use custom application URLs in the form: myApp://... iOS will automatically launch the application if present. The logic for handling the 'not-installed' case has to be in the QR code scanning app. can be handled by the scanned website via a forwarding link using the iOS custom URL scheme (this might be useful for usage stats).
Additional info on implementing Custom URLs...

iOS Custom URL Scheme - get source URL

I'm working on an app which launches from a custom url scheme.
I've managed to get the url and its parameters and everything, however, our app launches a web view. we want that when the user clicks a link with this scheme, the same page he is on would open up in our web view (it's needed because other functions run in the background, and allowing the user to keep browsing the website he was on)
Is it even possible to get the location of the clicked url? I know I can get the source application, but is there any way (other than adding the link to the scheme itself as parameters) to get the source link?
Thanks!
If you need information passed in to your application, that information must be somehow represented by in URL itself.
Adding a generic interface for that purpose wouldn't make sense as those URLs could be hosted inside an email message or an SMS, for example.

How to relaunch an app like facebook-ios-sdk does?

Question:
I am actively looking in the source code on Github's facebook-ios-sdk project myself but I was wondering if anyone already knows how to relaunch an app that sent an iPhone user to Safari, such that the user can come back after some work has been finished?
Example:
When using facebook to login, the original app is relaunched after the facebook login page has authenticated the user.
Motivation:
I would like to be able to do the same for youtube videos without having to completely lose the user. I don't want to use the standard webview approach because I don't want to provide extra space to first let the video load for the user and then have the user click the play button. I want to skip the play button and its associated click entirely! Instead I want the user to be able to click on just an everyday regular iPhone button and be shown the video with the navigation for coming back to the app via relaunch.
You need your app to register a "custom URL scheme". Then get the callback in the remote web service to return a URL with that scheme. iOS will then launch your application.
More (somewhat old) info available here.
A list of common custom URL schems on iOS can be found here.
Generally, as part of the OAuth login process, you supply a callback URL as one of the paramaters. What this does, is tell the remote server (YouTube), that on successful authentication, redirect the user to the supplied URL. If YouTube supports this (does it support OAuth?) then on successful user login within safari, youtube will tell users safari to redirect to the supplied url. If this url is a "custom URL scheme" it will cause your app to relaunch and you can handle the situation from there.

iPhone: launch app with YouTube URL?

I want to register a custom URL scheme that will enable my app to be launched whenever the user goes to a YouTube URL (http://www.youtube.com/watch?v=VIDEO_IDENTIFIER) in the browser.
Is this possible?
Edit:
After poking around I realized that YouTube's URL scheme is simply youtube://. What I want to do is that whenever there is a call to YouTube with the URL scheme, I want my app to be launched instead of the YouTube app - is this possible? What happens when there are conflicting URL schemes?
URL scheme is the thing preceding ://. It means you can't assign your app to handle youtube urls or any other http urls.
Update
Although Apple mentions YouTube URL Scheme in the docs, in the context of implementing custom URL schemes only the part before :// can be specified.
Update 2
Regarding your updated question. I'm pretty sure Apple wants YouTube app launched for youtube:// URLs. Since I haven't found an explicit note about conflicting URL schemes, I can't tell how the OS chooses an app to launch in general for a custom URL scheme.
As for the URLs handled by the built-in apps, they are very likely to remain so, i.e. it's impossible to override a built-in app and handle an http:// or a youtube:// URL with your own app.
You can do that and it will work on the simulator but the app will never get past the App review process.
On a side note, why would you want to do such thing as redirect youtube urls to your app, it's at least confusing to the user.

How do I get the Twitter API to respect the callback parameter with OAuth?

I'm working on an iPhone app that ideally uses OAuth to communicate with Twitter. I know a lot of people are doing the OAuth workflow inside of their apps using a UIWebView, but I don't agree with that and am going with the Pownce approach.
The problem is, Twitter has this whole scheme for working with desktop apps, using a pin number. When I register my app with Twitter, they have a web form asking me if I'm a desktop or web client. If I choose desktop client, when I try to have the user authorize, I can set the oauth_callback parameter but Twitter will ignore it after authorization and show a pin number. If, on twitter's form, I specify that I'm a web client, it requires me to enter a URL to redirect to after authorization. And, since I'm using an iPhone app-specific url scheme, their web form fails on validation as it only seems to accepts URLs conforming to the HTTP protocol.
So, it seems like I'm stuck - I can't say "desktop" because I don't want to bother with a pin, and I can't say "web" or I can't use an iPhone app URL. Any solution to this?
From your question:
I know a lot of people are doing the OAuth workflow inside of their apps using a UIWebView, but I don't agree with that and am going with the Pownce approach.
The Pownce article suggests that quitting your application and opening Mobile Safari to perform the authentication step is problematic, and that they started receiving bad reviews from users for doing it that way. They also experienced a failure rate of around 40%.
Pownce's solution is to use a UIWebView within your application instead, so I have a feeling you may have misinterpreted their recommendations. That being said, they do label this as a "naive" solution and go on to suggest a bunch of theoretical "ideal" solutions.
Another point you might not realise is that desktop applications (using the "out of band" / pin number method) and web applications need to open the Twitter site in either an embedded or external browser.
So you've got two choices on the iPhone:
Open up twitter.com in a UIWebView, specifying no oauth_callback parameter or oauth_callback=oob to start the pin-based out-of-band flow. The user then needs to copy the pin using the iPhone's copy-paste functionality, manually close the UIWebView, and paste the pin into your application. The pin can then be used converted to an access token.
Do it how everyone else is doing it (UIWebView + custom-uri://foo.bar in the callback parameter).
For obvious reasons, the first option is pretty crap and really only useful on platforms where Twitter is unable to redirect to a custom URI.
A simple solution may be to create an HTTP page that always sends a 301 redirect to your custom URL scheme and then provide that HTTP URL to the twitter web API.
Aside from that, Nathan's answer is very complete.
Here's how I do it: tell Twitter you're a web app, and make up any old HTTP:// URL to satisfy Twitter during registration of your oauth client.
Then in your app, pass the URL you want to in the callback parameter. Twitter (in my experience) uses the one you give it.
You could use an intermediate website for the authentication. Your app creates a unique id (hardware based?) and stores it. It then records it has sent the user for authentication and sends the unique id to your website. It then redirects the user to your website. Your website then sends the user to Twitter using oAuth. The user returns to your website and you mark the unique id as authenticated and store the authentication information. The user restarts the app on the iPhone, it reads it has sent the user for authentication and contacts your website with the unique id - and reads in the authentication information.
Long winded and needs another website, but it should work.