Swift - Check if website visited - ios

Is there a method or way in Swift to check if a user has visited a certain webpage or website?
I know a question was asked for this already:
How can I access browser history in my iOS project?
Or, maybe, is there a way to track if the phone has made a request from a certain IP?
I just want to create a condition to see if a user has visited my website.

No.
Due to the application sandbox for third party apps, you cannot track/access previous network requests outside your app.
Learn more about app sandboxing here.

The only way I can think of doing this is to get current IP of the user:
Swift - Get device's IP Address
Then do a get request to see if it is in my server logs. But this is not very reliable as they may have visited the website on a different network.
Could request a location one the phone and on the browser then compare lat and long to see if in a radius... still, not a reliable solution.

Related

What happens when you try to log into Facebook from behind China's great firewall?

For a few clients now, I've had a request to hide the "login with Facebook" feature in China, where Facebook is blocked. There are a couple ways I can think of to do this:
1) Use device locale.
Advantage: super simple!
Disadvantage: Inaccurate— someone in China could have their device set to en_US, and someone in the US could have their phone set to zh_CN. No dice.
2) Use GPS and reverse geocoding.
Advantage: You are actually measuring if the person is currently in the territory you've marked as 'restricted'.
Disadvantage: Requires the user to give you location permissions. Unclear what to do as a fallback if the user declines permissions. Some apps don't use GPS for anything else, and adding it just for this would be overkill.
3) Use a reachability check to http://facebook.com.
Advantage: You're going beyond checking whether the user is in an arbitrary location and actually checking to see whether facebook is currently restricted. If China stops blocking Facebook, your app starts supporting it immediately.
Disadvantage: You end up hiding the login UI if you're offline (which might not be a huge problem, because Facebook login won't work offline no matter where in the world you are).
Big unknown: What happens in China when you try to log into Facebook? Does it return a 404? Redirect to another site? Google searches around this (as linked above) just return things along the lines of "how to get around the Great Firewall" rather than "here's what actually happens when it's blocked".
So, the question: What happens when you try to log into Facebook from behind China's great firewall?
Trying to access Facebook in mainland China would result in error, like 403 Forbidden or 404 Not Found.
GPS Might not be a good idea, because the GPS signal in China is drifted, and as a result many cities located on the boundary would get overlapped GPS position, including southern Shenzhen/northern Hong Kong, Zhuhai/Macau, NE China/Russia and such.
How about reading the Mobile Country Code? So that users who are using Chinese sim card in their iphone can be identified and the option for facebook login can be disabled. But this trick would not be useful on iPod/iPad. It would also affect Chinese users roaming outside their country. How about checking if the IP address belong to a Chinese ISP?

How we can detect firewall or sonicwall redirect for our normal request in iOS devices ?

So here is the question
Many times you start your app and and your first API request fails and you realize that even though you're connected through internet You need to login in to Your office' or home network's firewall or sonicwall and login there
So you need to open safari and open your sonicwall page and login there and come back to our app and start it again.
I want my app to detect the same and show the the redirected html page in UIWebView and once the authintication finishes i want to execute the original request withing my app
My question is
1> Is it possible ?
2> If yes how can i achieve it ?
I would suggest using the same captive portal probe URLs that Apple uses in iOS Safari, for maximum compatibility. If those URLs return 200, you shouldn't be behind a (good) captive portal, assuming I'm remembering the details correctly.
You can beef that up further by using reachability APIs to detect network changes, and probing that URL, along with Google's generate_204 URL. And in some places, you'll find Google blocked (China, IIRC), in which case you might also consider a URL with a known, predictable, machine-validateable value, such as Apple's root certificate URL. :-)
When the user signs in, you should get another reachability change event, at which point at least one of your captive portal probes will succeed, and you can reissue any outstanding requests.

Sending orders from website to iOS app

I try to explain as best as I can (and simplify a bit).
I have an iOS app, asking the user 5 questions, 1 to 5 in this order. The questions are inside the app and the answers are then sent to a server via AF networking. It all works well.
I want to develop a web site with these same questions so somebody can choose which questions to be asked and in which order, for example 2, 5 and 3 only and in this specific order. Of course it will vary with each user. I then need to send this information back to the app and I want it after that to be Internet independent. I mean the questions and order are sent to the app (downloading or uploading) but then the user doesn't need Internet anymore to answer the questions (if there is no Internet to upload answers to server, the answers are automatically already saved in my app).
This surely must be possible but I don't see how exactly.
Do I need to have the questions in my app (as now) or having them on the web site would be enough?
How do I tell iOS to do something from my web site?
...
I am not after a precise tutorial, just some ideas thrown together to get me started, please.
Thanks a lot in advance for your thoughts.
Do I need to have the questions in my app (as now) or having them on the web site would be enough?
It's a good idea to have them in the app, so if the app is first opened with no internet connection it will still be usable. Each time the app is opened it should try to get new data from the web service and update its internal store.
How do I tell iOS to do something from my web site?
Generally, you don't. The app checks at appropriate times (like each launch).
Based on your comment below, the app should ask the user for his details and that is the trigger to connect to the server and obtain the active questions and order information. This can then be stored locally and the question interface can be presented to the user. Note, you could also return the number of days that should be recorded from the server...
On the next launch, you check for the existence of stored active questions and order information, and if you have some you go direct to the question interface.
The user should be presented with an option to upload the results (at the appropriate time), and you should have a setting somewhere to clear everything (just to remove the data, but also if the user needs to 'login' with different details for a new test session - so the app will check with the server again).

How to share links via FB App when I am offline

I am developing an mobile app for iPhone. The app will primary used by people who are on holiday in a different country and will be offline most of the time, due to high costs for internet traffic.
However, the company for which I am developing the app wants to users to be able to use the "Facebook Share" functionality also when people are not connected to the internet.
It should work on a way that they click the SHARE link button in the app, but then get a message that they are offline and the link will get shared as soon as they are online again.
I am trying to figure out how to do this. Can I pass the link I want to share to the official FB App via fb:// protocol (or whatever) and the FB App handles the post/share as soon as it is online again?
Or do I have to do it on my own, put the links I want to share in a internal database and then post them to the wall when I am online again?
Or any other ways??
Any suggestions would be welcome, I would prefer a very quick solution and hope someone maybe has an idea how to do this. I was hoping I can pass the share-link to the official FB App and this one handles everything when it goes online again !?
Thanks for your ideas!
Your approach should be to make your link-sharing code automatically cache requests until they are sent. The app then doesn't need to concern itself with the details - it can just post the link and get a 'failed', 'success', or 'postponed' response from your API and notify the user accordingly.
Your link-sharing code can then internally check if it can currently post to FB and if not (either because the user is currently offline or perhaps the Facebook token is expired) it will store it for later. This class will then re-check periodically (for example when the app comes to the foreground or when the class is initialised the next time the app starts) for connectivity and then it will check if the token is still valid and perform FB login if required. Once it has a valid token it can then iterate through the pending requests and act upon them.
If you really want to make it nice and clean, you can separate out the code that accepts incoming requests to do something, checks if it can be performed now, does it or stores it for later, and periodically checks any requests in the pending queue. This class will not have any idea what the requests do or how they are performed, it will work with another class that implements a protocol to do the actual work and knows about facebook, etc. There may even be an existing design pattern for such a setup, but I don't know what it's called if there is.
Update: I did some research and found this is very similar to the "Fire-and-Forget Pattern".

Inviting users to an IOS app

After registration, our app prompts users to invite her friends (aka phone contacts) to use the app too. This allows us to send an email/sms to the useer's contacts with some sort of invitation key. Works fine for a web version app, just embed the key in the url you provide in the invitation.
I'm having trouble figuring out how to make this work smoothly with IOS only. It would be brilliant if I could send the invitee a link to appstore.apple.com/myapp?registrationKey=abcXYZ and have the key magically available to my app once it's installed, but I guess this is a lot to hope for?
The obvious way around this is to make the user manually enter their registration key on first launch, but this seems less reliable and (to my mind) adds friction to the UX.
Has anybody come up with something clever to get around this?
Here is what is flowing through my brain on how to solve this solution, please note, I have not vetted, psudeo-coded, coded, or applied this theory.
Since you will know who is being sent an invitation, save that data to your database with a relationship to the user sending and a unique id to the user being invited (email address if its in the contact's card). When new users sign up scan the database for invitations, if one is found present it to the user asking We're you referred by <existing user>? Once the new user selects their response continue through the registration process, updating the relationship table accordingly and applying any extra settings you need to for the referral.
This combines automatic referral tracking with referral codes for a basic, straight-forward, almost (but not quite) fool proof method to make sure referrals are linked to the right users.
As far as I can tell, the App Store provides an information firewall between an invitation and the installed app.
The closest workaround I've seen is the following:
email link sends you to your website
the website logs reference information in the URL and the IP address
the website instantly redirects you to the App Store (if iOS detected)
user installs the app
user loads the app
app contacts your website, IP addresses matched ... BINGO
Obviously not a secure method though.
There are many failure cases:
business networks commonly share IPs
home and mobile networks release and reuse IPs
The more is frequently used to resolve cases where its good enough to know that the user 'almost-certainly' was referred to download app by the email.
For example, it can be a good mechanism to prompt the user with a "who do you know" question in an app and limit the options based on the (IP+reference) data. If they pick the original poster, then maybe that's good enough, and then you can attach any other data that the inviter provided.
(Full disclosure, currently work at Branch)
The best solution to this is to fingerprint a user. This requires you to do the following steps:
For each user, using your own domain, generate a link for said user. So, right when they complete registration, generate their unique URL, that contains the invitation key.
For anyone clicking this link, they will redirect to Safari first. When they do, capture their IP address and iOS operating system version from the headers and user-agent.
Save this data on your server, and set window.location to your iTunes url.
If the user downloads and consequently opens, inside AppDelegate.m, send a message to your server with the IP address + major/minor/min version you collect upon app launch. If it matches with what you have on the server, you can now pass that invitation key back to the new user.
It's not perfect, and has the ability to misattribute. You could also use branch.io, where all of this is taken care of (link-generation, fingerprinting a user, attribution). Branch also drops a first party cookie and ties it with the device level ID, so attributions are much more accurate.

Resources