Is there an easy way to swap between sessions in iOS WKWebView? - ios

In Android, we can simply just call the .contextId(...) method and supply a custom string to swap between sessions. This allows functionality such as the ability for users to be logged into multiple accounts simultaneously, similar to tabbing between different web views.
In iOS, Is there a method similar to the .contextId(...) for WKWebView to easily switch between different user sessions, or is the only option to use JavaScript injection to manually read/write from the localStorage and document.cookie variables?

Related

Using content providers/loaders on API Calls with no database changes

I am creating an application that does not store any data (other than basic user name, password, etc). It uses API calls to get data and displays them when loaded through Volley.
I know typically it is best practice to use content providers and loaders when you store things in SQLite. My question is: should I still be using content providers and loaders given that my app does not utilize a database. Does anyone have any best practices/tutorials on how to do so with Volley?
Thanks!
It depends on your use cases. But here, no there is no need. There are other callback mechanisms you can use like broadcasts, async tasks, handlers or even content observers. There is a nice official tutorial of how to communicate with the UIThread aka. the visible stuff from some background logic.
Also if you want to you also can use loaders without any content provider. See this so post for more informations.

Store global strings in iOS in Swift for app-wide use

I am designing an app which has a login screen. When the user enters username and password, a call to web service is done which returns a token on successful login. Now I need to send this token to every HTTP call inside different screens across the app.
I want to achieve similar functionality like this: Where to store global constants in an iOS application?
As there won't be any .h and .m files in Swift, how do I store these global strings (Note these are not constants, these are global variables) that I need to be able to access in any view controller
This is what exactly I wanted: Sharing strings and variables throughout ios app
I am able to share strings such as apikeys, tokens by using NSUserDefaults
saving:
NSUserDefaults.standardUserDefaults().setObject("apistringhere", forKey: "apikey")
NSUserDefaults.standardUserDefaults().synchronize()
getting:
NSUserDefaults.standardUserDefaults().objectForKey("apikey")
First off, using global variable is not the right answer to most questions. You should rather have an object that takes care of communicating with the web service and that object should also be responsible to tracking login state and tokens. If URLs changes, you'd have to only change them in one place and the code processing the data doesn't need to care where the data come from.
That being said, you can declare a global variable or constant in Swift just by declaring at the top level scope of a file, outside of any functions, methods, closures or types. You can also modify the visibility of the variable/constant with the access control keywords.

How many ways to share data among activities in monodroid?

I need to share some sensitive data among activities.
I have two EditText which are basically username and password
I am consuming a webservice which on the base of provided username and password return some user info (DataType:String). Like userid,useremail etc.. which is basically in CSV format
I need these piece of information throughout my application.But i can't figure out which is the better way.
-- One way i could found out so far is to use sqlite with MonoAndroid
-- Other way i found out is using Application class
I just started to learn android today , but i want to know if there are some other ways to share data ?
As you mentioned, a global Application class and the database are two good ways to share application-wide data. One thing to be careful with is that your Application class could be recycled when the app is in the background, so you would lose any data that hasn't been persisted to something more permanent.
In addition to the database, you can also persist data down to the filesystem as well. This recipe from Xamarin has an example of writing directly to a file. Most of the classes you'll need to do file access are found in the System.IO namespace. Mono for Android also supports isolated storage, which provides a higher level API for reading and writing files.
If you simply need to pass data directly between activities, you can do so by adding it as an extra to the intent. This recipe explains how to do that.
If you want to wrap up access to a particular resource in a more managed fashion that can be accessed by either other parts of your application or even external applications, you can look into implementing a content provider. Android itself provides several built-in content providers for resources like contacts and media, if you need an example of what it's like to use one. This recipe explains how to read from the contacts provider.

Rails: How to separate static content and application but while maintaining a connection between the 2?

Ok this question might sound a bit weird, let me try to explain what I am trying to achieve here.
I need:
- some mostly static pages: home page, about us, etc. the usual suspects
- a full complex rails web app
The web app being the heart of the system will have a lot of stuff, including user authentication (with devise by the way). The application will have a standard navigation menu with possible actions changing depending on user status (login or not, admin or not, etc).
Until now, nothing out of the ordinary.
However for unrelated reason, I MUST have the entry point of the whole system be the home page that will be hosted on another server (ergh).
So now, since my home page and other static pages will be on server A and all the application will be on server B how can I maintain contact between the 2 ?
Meaning: keep my navigation menu dynamic even on my static pages, have a sign-in / sign-up form on my static server but registering an account on the "real" application server ?
They can share the same database, no pb there.
Any pointers on how to do this ? I would really like not to put some iframes on the static site...
Thanks !
Alex
For the signin/signup stuff, you can have your forms action going to B and redirecting to A.
To display the right stuff in the menus you can make a jsonp call(as Chris said) to fetch either the entire header or specific parts of the header that are dynamic.
If you are just looking to include the users name, you can also simply store their name in a cookie and then use javascript to display it in the header.
If there's no cookie display a link to login/signup.
edit: For the jsonp calls take a look at a javascript framework to make the call client side, I personally use jQuery http://api.jquery.com/jQuery.ajax (and look at the jsonp options).
Thinking out loud...
Can you dynamically build the menus using javascript/AJAX in the static code? Perhaps that could query server B (via jsonp) to determine the options...
Its going to have do some "funky" (tm) stuff to track whether there is a user session or not... and linking them...

BlackBerry - Handling Custom Protocols

I'm currently developing a BlackBerry application where I need to be able to open the application by clicking a link in an email or web page. The link would contain a string of text that would also need to be made available to the application at runtime.
The iPhone OS allows you to do this through custom protocols (ex. appname://some-other-text) quite easily. Is there similar functionality available in the BlackBerry SDK, or is this going to turn into a pipe dream?
I have done something like this by registering a custom BrowserContentProvider (using a unique, custom MIME type). You then use a URL that returns an web page with the custom MIME type, which will trigger your BrowserContentProvider implementation. Part of this implementation can consist of code that launches your application (or bring it to the foreground if already running).
There's another class called ContentHandler that you may want to look into as well. I haven't used it, but it appears to be able to spawn custom handlers based on certain filename-matching conditions.

Resources