7

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:

  1. Use a weblink, open safari, and then come back to the app. This takes time.
  2. Use html tags <a href=myAppName://someQuery?blablabla=123">Test</a>, 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

Sulthan
  • 128,090
  • 22
  • 218
  • 270
Legolas
  • 12,145
  • 12
  • 79
  • 132
  • it sounds like you are embedding a web view within your app. And within that view is HTML that contains a link that the app understands and can respond to. Like a "Goto user profile" link that will cause the app to open the user profile screen. As users don't see the raw HTML, why do you need to hide the links? Also, I don't understand what you are doing in option 2. – drekka May 11 '16 at 02:05
  • 1
    Best practice questions aren't really a good fit for Stack Overflow. – JAL May 11 '16 at 14:17
  • I cannot say I got your question. How exactly are you using the URLs? Where do they come from? How are you presenting them to the user? – Sulthan May 12 '16 at 09:14
  • "and that is super slow, and buggy." show some code. In some test application I was building very large attributed text (+5k characters) and I didn't seen a big performance hit. – Marek R May 12 '16 at 21:43
  • You do have different different Encryption and Decryption schemes like AES, SHA, MDM, you can implement or use any for your intended functionality. will work like charm.! – iShwar May 17 '16 at 12:47

2 Answers2

4

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.

Community
  • 1
  • 1
Hemang
  • 26,840
  • 19
  • 119
  • 186
1

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.

hatfinch
  • 3,095
  • 24
  • 35