Accessing safari session data from iOs app - iphone

I have a web page that redirects to the appstore, once the user has installed the app I'd like it to go fetch some data based on a parameter passed to the web page.
so http://myapp.com/?q=123 redirects to app store for app installation, once the app is opened it should go fetch data from something like http://myapp.com/data/123
Would it be possible to start a session on the web page and store the 123 there, and then make a call from the app to any page on the domain and retrieve the 123 from there?

As far as I know it is not possible to pass some value to the appstore that will then somehow be retained for the app when/if it is installed. What you will have to do is find some means of identifying the user or device both on your site and in the app. Anything from a username, email, facebook account will do. Anything like device ID and MAC addresses are pretty much off limits as well, if not impossible. I hope this helps, or maybe there is another solution out there that I do not know of.

Related

Should Facebook canvas apps behave same if opened from original non-canvas site url?

This is a first time I am trying to make a facebook application/game, and I have couple of questions.
Let's say canvas url is http://mysite/first_app/ and facebook app url is https://apps.facebook.com/first_app
I wonder if visited both url-s should a functionality be the same? I mean does facebook give you more tools and freedom if navigated from https://apps.facebook.com/first_app? Or should both url-s look and do the same thing? Is it possible?
I wonder if visited both urls should a functionality be the same
Of course yes. The difference is just that one is deployed at the facebook's app center and the other at your domain.
Yes, you have more tools available in the canvas ("apps.facebook.com.."), as it will send you the user-id without any user consent. Has the user previously used your app, you will also be able to get their accesstoken and fetch more info about them.
It requires some backend code to decode the signed request parameter, which provides you this stuff.
This example is how php handles signed request:
https://developers.facebook.com/docs/facebook-login/using-login-with-games/
If you're using C#, download the Facebook C# (available through NuGet, the package from Outercurve Foundation) and use this example:
How do I parse a signed request in Facebook C# SDK?
I try to handle the user in Facebook context whenever possible. It adds trust and more tools. Although since the Facebook phone/tablet app (App Store/Google Play) doesn't support Facebook apps at all, I often optimize the app for mobile web use also. I read somewhere that over 50% of daily Facebook visists are done using the phone app, so it might be something to think into your app while developing.
UPDATE:
I can see I have misunderstood part of signed request, as commented by Shadowfax and CBroe. In my app, I use the user id from signed request but of course only when the user has already logged on to the app beforehand. My apologies.

How to launch iOS app via custom URL and allow to open a webpage if it's not installed?

I'd like to be able to send invitation in an email to a specific "event" happening inside my iOS app. So I figured I'd need to use custom URL. That's fine.
But I'd also like to be able to handle the user that doesn't have the app installed yet, to be taken to a mobile Safari and to the webpage with installation instructions for the app.
What would be the best way to do it?
I could try the following:
In the email I send a link to a http://www.example.com/joinevent/?id=foo
User is taken to a Safari webpage that sends a redirect to mycustomscheme://joinevent/?id=foo
If the user doesn't have the app installed this redirection won't work and he stays in the Safari - I could then handle the displaying of installation instructions probably.
But this approach doesn't seem "natural" for me. Is there a better/more native way to do it?
Try http://rdrct.it
It is a web service that allows you to achieve exactly this functionality very easily.
Full disclosure - I created rdrct.it
Here's the basics:
Login to the site, create a project for your particular app. Choose a unique code (this could be the name of your app).
You'll then be provided with a URL in the form: http://rdrct.it/uniqueCode
Once you've done that, you need to register the app's ID in the app store, and also details about the custom URL scheme. Tick "Auto-redirect" - what it will then do is try to open the app, and if that fails, it will automatically send the user to the app store.
If the app is opened, then the querystring is also passed to the app, so in your example case, the device will have been served: mycustomscheme://joinevent/?id=foo
It also works across multiple device types, so if you have the app available for Blackberry, Android or Windows Phone, then it will also do the same for those depending on which device type the user is using.
Like I said, I created it, but it should solve your problem.
If you are using Distimo to track you app analytics, they provide a shortlink to your apps that can be used also used to track conversions. It shows a custom page depending on the device used to access. This is especially convenient if you have the same app published in the AppStore, Google Play, Amazon, etc.

How to get the current appID from url?

I have an app in facebook, and I want to use this very same system on a different app as well. I have all data stored in a database (appid, appsecret, pageid etc), but if I load the app in facebook, I can't figure out what appid the current app is.
For example:
When I visit app_1234567890123456, my app has to figure out like "hey, this is app with ID 1234567890123456, let's see if I have that one in my database"
But now my app is more like "wtf? I really have no clue what all of this is".
I know facebook has this thing $facebook->getAppId, but in order to do that, I need to connect with facebook with an app secret and an appid, and those are 2 things I don't know at that moment.
I can only make the connection with facebook if I know the appID from the current url.
When a user goes to your canvas app inside facebook, facebook is posting the data to the url you've set in the app settings.
The data you get with that post is the signed request which, unless loaded in a page page, does not include app data.
The sdk you have on the server side (from your code looks like the php sdk) is not aware of the app data, and you need to pass it to the sdk yourself, and because of that you'll have to figure it out yourself.
What I suggest that you would do is to have different canvas urls for the apps, so:
app #1 gets: example.com/facebookapp1
app #2 gets: example.com/facebookapp2
You can have the same system to serve those urls, and it will act the same for both except that it will know which app the user asked for.
You can get the Facebook Page ID from the signed request parameter
http://developers.facebook.com/docs/authentication/signed_request/
Depending on your implementation, you could perhaps use this instead?

Wordpress Background (Mobile) Web Authentication

I'm building an iPhone app that, in part, allows the user to log in to, pull data, and post data back to a Wordpress site (more specifically, Buddypress). One way I'm considering approaching this problem is to use a series of UIWebViews to display the mobile-themed version of the site.
Ideally, I want the user to be able to, upon first-launch of the app, input their username and password, and then never have to do it again (functionally similar to tons of other social apps out there, like Facebook, Twitter, etc.)
Here's my question - obviously it is easy to store the user's login credentials, but how do I, in the background, establish an authenticated and persistant session with those credentials each time the app opens, so for the user, they are never presented with a login screen again, and can just use the app like normal?
Does anybody have any suggestions?
WordPress uses XMLRPC to authenticate. You can, on top of the API given, write your own codes to store credentials. Persistent session can then be made.
Read this FAQ : XML-RPC Support for WordPress

iPhone: Pass information from web page to app that's downloaded from App Store

I'm trying to glue information from a web page to an iPhone app that said web page suggests to download. I control both the web page and the downloadable app.
Scenario is like this:
User visits my web page, on which I recognize the user (he may have logged in, and I store his info in a cookie). I then present a link to him to an app in the App Store that he should download for "enhanced experience" of this web service of mine.
Now, when the user launches the downloaded app on his iPhone, I like to re-identify the user who previously visited said web page.
All would be easy if an iPhone app could read Safari's cookies. But it can't.
A somewhat lame solution could be that the web server stores the visitor's IP address and uses that to recognize him once he launches the iPhone app. But that's not reliable.
Another one would be to give the user a token (code) that he needs to remember and then re-enter in the app. Still quite awkward, I think.
Any better suggestions?
Simply put, you can't do this.
One thing you could consider is a custom URL scheme to launch the app. You could send the user an email that uses this custom link. However there's a couple of problems with this:
the user may not have the account that they used to register for your site set up on their iPhone. This might seem unlikely, but say the user signed up for your site 5 years ago with their Hotmail account and they have since switched to Gmail.
it's unlikely that the email would fit into their workflow. They would probably download the app and just launch it by touching the icon instead of clicking a link in a received email.
You could also put the custom URL as a link on your web page, but again, this won't fit into the workflow because they have to go to the App Store app to do the download.
Consider this - if you've got some sort of website that has an authentication step, it's probably a fair bet to say that the user is the type of person who already has an application such as Facebook installed on their iPhone. They are already used to the paradigm of having to enter their credentials into an application despite the fact that they may have already done it in Safari.
If you could read the unique iPhone device ID from javascript on your web page, you could look for that again when the application connected...
But I cannot find any means of reading this from Javascript in Mobile Safari, I thought I'd post in case there is a way now to give you another option to consider.
OK, we found a somewhat working solution: The html code can create a cookie. Later, when the app runs, it can't directly read that cookie, of course (due to the sandboxing of iPhone apps). However, it can connect to the server, then open a http URL pointing to the server and including a unique token that it has gotten from the server beforehand. This leads to launching Safari, accessing the server. The server can now read the aforementioned cookie and finally establish the connection with the help of the token.
Just stumbled over this question and I'm curious if you thought about using a UIWebView.
Where the question is - does UIWebView share cookies with safari?
If it does the rest should be easy.
UIWebView's DON'T share cookies with Safari. So unfortunately that is not an option.