UITextView intercept mailto links - ios

I've found several places showing how to subclass UIApplication.openURL which is called when a user taps a hyperlink in a UITextView. However, I'm finding that this is not called when they tap a mailto link, and I only need to override mailto links. My app includes an email client, and since Apple will not allow me to make my app the "default" email client, I at least want mailto links inside my own program to use my app for sending email.
I first tried using a UIWebView instead, which did allow me to do this, however that had some display issues (I'm just displaying plain-text and it doesn't look/work as nice as the UITextView for that).
I have also tried overriding UIApplication.canShowURL but it is never called, not even for http: links. I've tried subclassing and also "Swizzling", both give same results.

Based on info I found here Possible to handle your own http URL schemes in iOS?, from the comment by kineticfocus, I ended up with:
Register for a custom URL scheme http://mobiledevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html.
Before displaying my text in the UITextView, find each valid email address and mailto: URL and convert to my custom URL scheme. Example conversions:
example#sample.com -> myapp://example#sample.com
mailto:example#sample.com -> myapp://example#sample.com
This isn't ideal because it makes the text harder to read due to the conversion (not so much for the mailto: URLs but for the plain email addresses in the text it does), but was the best I could find without going to a UIWebView.
I was impressed that the UITextView supports custom URL schemes -- In the Windows world I've always wished the RICHEDIT window class would support that, but it doesn't.
Only posting this as an answer instead of reporting my question as a duplicate because most everything else I've found is not related to UITextView, they are either using UIWebView or just want to invoke their app from another app or website.

Related

How to set a search engine in Firefox to redirect to an extension

I am developing a search engine extension for Firefox and I want to set it as (default) search engine using JavaScript. That means, if
somebody wants s/he should be able to type some query into the search field or the address field and the search should be redirected to the
extension. This is pretty easy to do when the target URL is a real address like http://mysearch.com (see this SO question and the relevant Mozilla Developer documentation), but it does not work if you try it with an extension URL
like resource://my-search-extension/search.html. Is there some way to still achieve this, e.g. by some hook listening on query inputs in
the search or address field?
P.D. You can set up a bookmark shortcut so that you can redirect a search like s keyword to an extension, but this not a convenient option
in my case.

Best practice to hide URL scheme from end users

I want to send text messages in the app that are links to open other views inside the same app. Like a notification text message which has links to other views in app. So the best way to go about this is to insert the URL scheme myAppName://someQuery?blablabla=123 and that should in turn fire the openURL command and open that specific view.
What is the best practice to hide the url scheme from the end user. It looks ugly and also don't want to create the possibility where end user can pass in values to the url scheme.
My options:
Use a weblink, open safari, and then come back to the app. This takes time.
Use html tags Test, but this takes a hit on performance as I need to keep assigning attributed text to the textView, and that is super slow, and buggy.
So far, the best option I have it 2. Just wondering if there are other good ideas out there...
Thanks for the help
You can encrypt your parameters string and then send it as a message
Encrypted URL form:
myAppName://encrypted_query
Now when you get a call in your app, you should fetch the encryptedt_data out of the URL and should decrypt it before actually doing anything.
Decrypted URL form:
myAppName://someQuery?blablabla=123
In my believe this is the best and easiest way to get this done. For encryption/decryption best practice check this, AES Encryption for an NSString on the iPhone and this.
As long as you're not concern about the security, you can always use reduced size of encryption string to make a URL smaller. That option is given in Github library.
So the best way to go about this is to insert the URL scheme myAppName://someQuery?blablabla=123 and that should in turn fire the openURL command and open that specific view.
I'm assuming you're using a web view and that's why you want to handle things this way. But are you aware of the WKScriptMessageHandler protocol in the new WKWebView class?
If you embed onclick='window.webkit.messageHandlers.yourHandlerName.postMessage(yourUserData)' on the web side, and setup one or more script message handlers through the WKUserContentController of your WKWebView, their -userContentController:didReceiveScriptMessage: methods will be called with yourUserData as the message body.

Canonical URL formatting issue causes Facebook to interpret mobile URL as a different URL

I need to format this canonical URL and I cant figure out how! I've looked around the web and this site a lot and I've realized that I need a specific answer.
Problem Description:
My BLOG's desktop view has (say) URL: www.x.com/page.html
The same page in mobile view URL would be: www.x.com/page.html?m=1
Its all good and dandy to this point, but the problem comes when I use facebook comments with this. It parses url based on this: www.x.com/page.html
So, it is identifying ?m=1 in the end of the first URL as an entirely different URL.
i.e
It is treating those two URL as different
Both of them are URL for the same page and I want them to be treated the same
Could anyone provide me a way to check if the loading page is ?m=1 and if it is ?m=1 then remove the ?m=1 when sending it to facebook?
I WOULD GREATLY APPRECIATE IT IF THE SOLUTION IS INLINE if it is not inline, oh well, I just need a solution right now.
Current code snippet used is this:
<fb:comments colorscheme='light' expr:href='data:post.url' expr:title='data:post.title' expr:xid='data:post.id' height='110' width='560'/>
Let me break the question into small parts(incase someone is not a native speaker and wants to help/learn about this problem)
I want to detect if the loading page has ?m=1 in its URL or not. The canonical URL for this is data:post.url applied as
expr:href='data:post.url'
If a ?m=1 is detected from data:post.URL , I want to remove it and send the remaining URL into expr:href= so that both my URLs
are identified the same when my website displays facebook comments.
Click the image link below to look at this image please. This is the same URL but the
comments are being sent to me as if they're from different URLs. I
want them to appear under the same thread.
This is it--> http://i.stack.imgur.com/M7fK2.png
I haven't found this particular answer anywhere and I am hopeful that
some creative solutions will pop out in this site!
In your code
<fb:comments colorscheme='light' expr:href='data:post.url' expr:title='data:post.title' expr:xid='data:post.id' height='110' width='560'/>
Use data:post.canonicalUrl instead of data:post.url
This is the Blogger's layout tag for getting the Canonical URL of a blog post (This will always default to the blogspot.com domain, so there won't be ccTLD issues as well)

how to avoid hardcoding external URLs into iOS App?

Whats the best practice to avoid hardcoding links in iOS apps?
I need to link to an external website that does a search based on the URL query string parameters.
Ex. "http://stackoverflow.com/search?q={query}"
I dont want to hardcode the actual url in my app because I don't want the app to break if the URL changes or the query string parameters change. I'd like to hardcode into my app:
"http://foobar.com?query=someString"
and then redirect that to my actual target, ie, "http://stackoverflow.com/search?q=someString"
I looked into URL shorteners (bit.ly, goo.gl, etc) but they dont allow me to change the target URL. Looks like a URL redirection service might work but I wasn't able to find one that handles query string parameters in the way I need.
How is this problem typically solved?
thanks!
Mark
Just add a text file (or similar) on your website with the URL(s) in it, fetch it occasionally from your app. Make the app parse the text file and use it to decide what URL it should fetch.

BlackBerry - intercept text in HTML

I would like to be able to intercept a hyperlink from an email on BlackBerry.
e.g.
dummy site
I have been able to intercept and identify text in a plain text email using PatternRepository. However, it doesn't seem to work with HTML emails - is this even possible?
I would like to avoid the solution of scanning every incoming email myself, and parsing all the text, but this might be the only option.
Thanks
This is not possible (up to and including BlackBerry 6 afaik). It is not related to the hyperlink concept - it is not possible to use PatternRepository with any type of text within HTML text.
For performance reasons, the BlackBerry designers decided not to implement pattern matching within HTML fields (browser, or email). This is very unfortunate, but it must be dealt with.
In my app, I had the freedom to define the contents of the email. In my case, I ended up including the pattern into the subject of the email - the user can click on the subject to get to my app.
In most other situations, I think the best/only way forward is to intercept each mail as it arrives and parse it looking for the text. If I have to do that in the future, I'll try to update this post with some sample code.
There are various posts on the BlackBerry forums about this issue.
Richard

Resources