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.
Related
I have given an option to my users to share my website on whatsapp. And I want to know how many users land back on the website using the shared link. Hence, the shared button opens this link:
https://wa.me/919876543210?text=https://www.mywebsite.com?utm_source=whatsapp&utm_medium=share
But this URL considers the end &utm_medium=share as a part of the wa.me URL, and shares only https://www.mywebsite.com?utm_source=whatsapp on WhatsApp. So instead I did this:
https://wa.me/919876543210?text=https://www.mywebsite.com?utm_source=whatsapp%26utm_medium=share
which shares the correct URL on whatsapp: https://www.mywebsite.com?utm_source=whatsapp%26utm_medium=share, but when I open it, the UTM params are not captured by GA.
What is the way out of this loop?
There's a more elegant way of doing it than utm params. Have something like: https://wa.me/919876543210?text=https://www.mywebsite.com?t=wa
See how now it's shorter and more elegant to a user? Now you have two good options.
Make a conditional redirect on your site from any url that has a t=we query param to whatever utm param you want with no restriction.
And even more elegantly: use GTM to parse pageviews where there's a t query parameter set, then make a neat lookup table where the input would be the value of t and the output - whatever you want to name it. Then use that lookup table's value to set your session-level custom dimension in pageviews.
Why a custom dimension and not UTM? Because when using UTMs, you're affecting your attribution. And sessions. You can easily override organic or paid attribution with some meaningless whatsapp attribution. Well, yes, if you don't use attribution at all and you don't care about GA session breakpoints, then sure, UTMs are just easier.
Also, try escaping the &, but not much hope there.
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.
Is it possible to create a new page using german special character in a url path (e.g example.com/prüfung.html).
The ü character can't pass validation, and if i try to change the validation rules so it can pass the validation, the page can't be accessed neither via backend nor frontend.
is it possible to do that?
I think currently we do not allow that. I can open a feature request and have a look at it. Would you explain why you need that? I mean is it better for SEO? Because actually this URL will be impossible to enter for some people not using a German keyboard.
I would like to hide the webpage name in the url and only display either the domain name or parts of it.
For example:
I have a website called "MyWebSite". The url is: localhost:8080/mywebsite/welcome.xhtml. I would like to display only the "localhost:8080/mywebsite/".
However if the page is at, for example, localhost:8080/mywebsite/restricted/restricted.xhtml then I would like to display localhost:8080/mywebsite/restricted/.
I believe this can be done in the web.xml file.
I believe that you want URL rewriting. Check out this link: http://en.wikipedia.org/wiki/Rewrite_engine - there are many approaches to URL rewriting, you need to decide what is appropriate for you. Some of the approaches do make use of the web.config file.
You can do this in several ways. The one I see most is to have a "front door" called a rewrite engine that parses the URL dynamically to internally redirect the request, without exposing details about how that might happen as you would see if you used simple query strings, etc. This allows the URL you specify to be digested into a request for a master page with specific content, instead of just looking up a physical page at that location to serve.
The StackExchange sites do this so that you can link to a question in a semi-permanent fashion (and thus can use search engines with crawlers that log these URLs) without them having to have a real page in the file system for every question that's ever been asked (we're up to 9,387,788 questions as of this one).
I am trying to implement Twitter's OAuth into my Code Igniter web application at which the callback URL is /auth/ so once you have authenticated with Twitter you are taken to /auth/?oauth_token=SOME-TOKEN.
I want to keep the nice clean URL's the framework provides using the /controller/method/ style of URL but I want to enable query strings as well, there will only ever be one name of the data oauth_token so it's ok if it has to be hard coded.
Any ideas?
I have tried tons of the things people are saying to do, but none work :(
PS: I'm using the .htaccess method of URL rewriting.
There are several ways to handle this.
Most People, and Elliot Haughin's Twitter Lib, extend the CI_Input library with a MY_Input library that sets allow_query_strings to true
You will also need to add ? to the allowed characters in config/config.php and set $config['url_protocal'] to PATH_INFO
see here: Enable GET in CodeIgniter
Codeigniter Reactor lets you access $_GET directly or via $this->input->get(). You don't need to use MY_Input or even change your config.php. This method leaves the query string in the URL, however.
I used a hacked index.php to recognise users coming back from Twitter, check for valid and safe values, then re-direct it to to a CodeIgniter friendly URL.
It may not be to everyones taste but I preferred it over allowing query strings throughout the entire application instead of just one particular circumstance.