Best practice to hide URL scheme from end users - ios

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.

Related

What's the best way to create a FAQ page for ios app

Many ios apps contain a FAQ or How to use page, when loaded, will display some FAQs in text format. The content is loaded from remote server rather than built in so the contents can be updated anytime with flexibility.
What's the best way to implement this type of page? My app does not contain any server side function except this page so I am really looking for a cheap (or free) way instead of renting a server just for this. Also, my FAQs will be static HTML.
Thank you for any suggestions.
The simplest way to display an HTML page is to use a UIWebView as the main view of your view controller and set its URL or file-path using the loadRequest() method of your view.
You can use this method for both remote FAQs (in this case you'll set an URL) and local and static ones for which you'll use a path to the file included in your project.

Sending data to form, but cant work out encrypted post data - work around

Im trying to send some data to a form on a site were im a member using cURL, but when i look at the headers being sent, they seem to have been encrypted.
Is there a way i can get around this by making the computer / server visit the site and actual add the data to the inputs on the form and then hit submit, so that it would generate the correct data and post the form ?
You have got a few options:
reverse engineer the JavaScript that does the encryption (or possibly just encoding) process
get a browser engine (e.g. the Gecko engine), and add some scripting to it to fill in the forms and push the submit button - of course you would need JavaScript support within the page itself
parse the HTML using an HTML parser, feed the JavaScript in it to a JavaScript runtime with the correct libraries, fill in the "form" and hit the submit button
It's probably easiest to go for the first option. The JavaScript must be in the open to be able to be executed in the browser. But it may take some time to reverse-engineer as it is likely obfuscated.
You can use a framework to automate user interaction on the web pages, like Selenium.
This would enable you to not bother reverse engineering anything.
Selenium has binding in various languages, including Python and java.
Provided the javascript is visible on the website in question, you should be able to simply copy and paste their encryption routines to prepare the headers exactly as they do
A hacky fix if you can isolate the function that encodes the data you type in the form - is to use something like PyV8 to execute the JS inside python.
Use AutoHotKeyIt and actually have it use the Browser Normally. It can read from files, and do repetitive tasks infinitely. Also you can push a flag to make it only happen within that application, which means you can have it minimized and yet still preform the action.
You seem to be having issues with the problem of them encrypting the headers and such, so why not simply use that too your advantage? Your still pushing the same data in, but now your working around their system. With little to no side effect too you.

UITextView intercept mailto links

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.

How could I make an app login in a website and get info in the background?

I think I am mostly struggling with this problem because I do not know what to search for.
I want to make an app that allows the user to enter their gift card number and use that number to login to this website:
https://www.getmybalance.com
I have no idea how to do this without control over the website. Is it even possible to do so?
I don't want to use a UIWebView to show the page.
You should read up on NSURLConnection, you're going to have to execute a post request to login. Then you're going to have to determine whether or not you logged in successfully probably by parsing the returned page. NSURLConnection will handle storing the login cookie the site returns. After you've logged in you're probably going to need to execute another post request to query their system. Once again you will have to probably parse the result out of the HTML page that is returned.
NSURLConnection:
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nsurlconnection_Class/Reference/Reference.html
NSURLConnection Delegate Protocol:
https://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSURLConnectionDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/NSURLConnectionDelegate
This all of course assumes that this website doesn't have an API you can use.
Looks like you need to programatically POST in https to the server, then you will get back some DOM document, or JSON, or some weird thing, which you then parse.
POSTing with iOS is pretty easy, look at something like LRResty https://github.com/lukeredpath/LRResty or similar.
When you get the data back, first thing to do is look at it with NSLog. Then if the data is HTML, you will need to wade into the HTML to get the result.
The problem with that approach is that the company hosting the page may change their API at any time. You should ask them to either not ever change anything (if they want to change, then make a new page and leave the old one working, or better, support a simple REST API - which would also help them build nice AJAX/html5 web sites in the future.).

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.

Resources