Get time difference in iOS when in offline mode - ios

I have an app which works both offline and online. I have a request from the client to embed a functionality which will disallow the user from using certain functionality after some days, 7 days, for example.
If online I can easily achieve this task by comparing the time-interval between server time.
But in offline mode, this has been a problem. I have tried to achieve this by saving server timestamp in USerDefault and when the app comes in the foreground, compare the current NSDate with the one saved to get time interval. But, what I found is this can be hacked easily by manipulating the date and time in Settings and those functionalities in app works perpetually.
Another solution I have thought is to disable the app if date time is not set to automatically in the setting. But, found that Apple has not disclosed the API to access date and time.
I have searched for other answers on the internet, but could not find the solution to fix this issue. Also, tried some offline game app to check but found that I can change date and time to manipulate their functionality.
So, isn't there any robust solution to fix this issue? Any help is highly appreciable.

you can manage timings on the server through API calls when the user
goes offline or log out or something. so you can easily get to know
your exact timing and it is also not hackable :)

Related

Security of app using Parse servers

I am using Parse servers for my app, and I am concerned about people getting into the code of the app and changing the code that communicates directly with Parse.
For example, if I save a score to the database and I want to update it with a new score by the user, I have to write that code within the app. However, if someone were to change the code and hardcode in a score that wasn't earned, they technically could.
Is there a way to prevent this?
(When I say getting into the code, there is a way to do this using a jailbroken device. I don't know if Apple has fixed this, but about a year ago someone I know showed me the code to an app that is on the App Store.)

Google API Changes causing problems on my App

I have an iOS App on the App Store, and it connects to Google Drive. In the past week or so, I've noticed two new problems in my live app.
The App suddenly stopped logging in. I would get a 401 - invalid_client. I found a lot of questions/answers for this problem, but they were all for people who couldn't get it working. Mine was working for about two years and then stopped working a couple of days ago. After trying a lot of things, I found that I was using <id>#developer.gserviceaccount.com as my Client ID, and when I changed it to <id>.apps.googleusercontent.com it worked again. I don't know why this change fixed it, and even knowing that this fixes it, I can't find if this is the correct/appropriate solution.
I explain my second problem, which is very specific here, but skip to the next paragraph to get to the point. The second issue is a a result of Google changing the way their API calls respond, and this is why this wasn't an issue when we submitted the latest version of the App to the App Store. Google has changed the way the explicitlyTrashed property of their GTLDriveFile class. Per their spec, this property should be either an NSNumber containing Yes, or null. They have recently changed it so that it is always an NSNumber set to either Yes or No. This is what's breaking our functionality.
Anyway, these are two changes Google has made on their end recently that currently has my customers on hold since I have to fix this and push it out. My question is if there's a place to keep up with these changes that Google is making recently. Also, if someone knows or can point me to why the first issue is happening, I would greatly appreciate it.
For the first issue, the reason why it got resolved by using [id].apps.googleusercontext.com is because it it requesting an authorization token from an app to the server, as opposed to a Server to Server transaction using impersonation ([id]#developer.gserviceaccount.com). This is the right solution for both android and IOS apps requesting a token.
As for your second question, the best way to keep up to date with the latest changes is through their official blog: http://googleappsdeveloper.blogspot.com/
Another resource is the G+ Google Drive Developer community: https://plus.google.com/communities/107264319205603895037

How to see if an iphone is synced if an NTP server?

I am coding in Xcode 6.1.1 with objective-c.
In my app it is critical that I use the correct time.
I only want the app to use the time of the device when the time is synced with the servers.
If an user is somehow using his/her own "weird" time the app should detect that and tell the user to switch back to use the app.
I know there is NSSystemClockDidChangeNotification, but that only gives back when the time is changed. It does not give back what the change was and if the user switched to "custom" time or synced back to an NTP server.
Question: How do I detect if an user is connected to an NTP server or not?
Maddy is right that you can't specifically find this out from iOS.
However, in the past I've delivered a client for a premium subscription service that had a similar need to know if the user was messing with time. In particular we needed to verify this when there was no network available, in order to prevent the user from accessing premium content after their subscription had lapsed. The very simple mechanism we used was as follows (IIRC):
every time the app launches or comes in from the background, record the current time (eg: in NSUserDefaults)
compare the current time to the last recorded time--if the current time is earlier than the last recorded time, force the user to go online and sign in to the service.
I don't claim it is 100% foolproof, but for our purposes we felt it was good enough to prevent users from trying to circumvent time-based restrictions on accessing premium content.

Find correct time on iOS device

I want to find out correct time on iOS devices even though user have set wrong time manually.
In the setting->General->Date & Time there is option of Set Automatically if that option is uncheck by the user then how can i find the correct time programmatically.
Use NTP protocol for getting a current time or serve a time from your server and get it on application launch.
Apple doesn't provide by default any way to get time from NTP unfortunately and all time related function are using local time that user can change.
I have a 'web service' on my site which serves you the current time in milliseconds since the Unix epoch, one request, one response, nothing else.
I think this is the wrong place for this question. Try Apple's forums.
Because there is no way to get current time form ios device when user update time manually.
Sweet & smart .........

What code is needed to be notified in real-time whenever my iOS app is downloaded?

I recently published my first iOS app and felt really dissatisfied with apple's iTunesConnect portal for tracking app sales. Specifically, I can't tell what time of day the app was downloaded, and I have to wait for the results until the next morning.
Does anyone know a piece of code that can be unobstrusively inserted in my app that will somehow report to me after if has been installed for the first time? I don't want any privacy/rules violations, I just want the app to report that it has been downloaded, and maybe a few metrics regarding country/time/etc.
Thanks for the help!
EDIT:
Regarding a first run 'phone home,' is it possible to execute some HTML without having the user knowing (I don't want to interrupt their experience by opening a webbrowser). For example, some javascript from a statcounter? If not, what can I do?
There are a lot of analytics tools that can help you get better metrics.
Flurry
Google Analytics
Mixpanel
Kissmetrics
Google analytics gives you usage information in real time, which is nice.
Also, if your users log in through Facebook, they provide some interesting analytics as well.

Resources