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

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.

Related

Make a Service call when app is not running iOS

I have one requirement that when user submit a form. I have to give user 30 minute time gap to edit the form. If he don't edit the form in 30 minute time interval , the form should be automatically submitted even if the app is not running. Can we make a service call when app is not at all running? If yes then how to do this. Please help.
To expand on Jasmeet's answer, you will need to change the server. You will need to submit the form at the latest in applicationDidEnterBackground:, though you may want to submit it much sooner than that (since the app may crash or the phone may be turned off, in which case you will never go into the background). If there are edits made, then you would submit the form again. If 30 minutes pass (as measured by the server), then the server will accept the form. You will likely want to include some timestamp information in the request so the server knows when the form was last edited.
There is no way to run code at an arbitrary time on the device. You must change the server code, or you cannot solve this problem. (Even if there were a way to run code at an arbitrary time on the device, it would not solve your problem, since the device may not even be turned on or have network access 30 minutes later.)
If you cannot change the server for some reason, then you will have to change your requirements. This cannot be solved as you describe it.
If you want to submit the form in background there might be chances the form will not submit if the app is suspended in the background.
you can submit a form first and if user edit the form within 30 min you can resubmit the form.
If you submit the app with background mode enabled and handling your work without Apple guidelines for background mode support enabled. Your app will be rejected. Please review the background mode support guidelines before taking up the appdidenterbackground call working. You may prompt the user to fill the data but don't autosubmit rather autosave and next time he wake up just restore the form so he can continue to have a good user experience.
Apple Guidelines to use background mode.
2.5.4 Multitasking apps may only use background services for their
intended purposes: VoIP, audio playback, location, task completion,
local notifications, etc. If your app uses location background mode,
include a reminder that doing so may dramatically decrease battery
life.
https://developer.apple.com/app-store/review/guidelines/

GPS location tracking of others in Corona SDK

I am building an iOS app in Corona SDK and am trying to implement a map feature where the user can see where they are compared to where others with the app open are. What would be the best way to go at this?
I already wrote the code for finding the current location of the owner of the device, but how do I retrieve data from other users?
Any advice is greatly appreciated!
This is very broad question, but basically you need a server (on the web) where each user's location gets stored while the app is open, and the app can request the location of other users specifically, at some time interval. Presumably you would need to have some form of rights management since every user would typically be interested in seeing only a small number of other users, and every user would want to have control over who can see their location.
One thing to remind users of is that the reported position is that of the device, not that of the user, and that it is the last reported position, not necessarily current (not all devices are on cellular network or wifi at every moment), so you'd also want a time-of-last-update to be shown with every location marker.

Passes in Passbook: location and time sensitive

As I understand for the moment, the location and time sensitive passes in Passbook only support time and/or location based notifications. So at the correct time and location, the user will get a notification for the pass.
I was wondering if these properties also can be used to change the pass. For example, if you are in some specific store, the coupon provides a 50% reduction instead of a 20% reduction. If it is not possible to do this locally on the iOS device, is it possible to send a request to the server based on location and/or date to achieve the same thing?
Sorry to be the bearer of bad news, but it's not possible to accomplish this.
Firstly, the data within the pass is fixed at any point in time. As you've said, it can be fixed to a list of locations and/or a date.
Secondly, the pass cannot communicate with a server except to request an update in response to a push notification. This means you will never know where a pass is.
The only option way to achieve something like this would be to generate passes using an app that is location aware, but I don't think this is what you're after.
You can send a push update to a Pass at a specific time. This way you can (for example) convert a 10%-off coupon to 20%-off on Fridays (and then switch it back after Friday).
After a user has initially 'Added' your Pass promotion into their Passbook you can update it at any time without requiring the user to 're-approve' your update.
Your server does not know when a Passbook user has triggered a location alert - otherwise you could track their movements via Passbook. Apple does not want their customer's security to be compromised in this way.
However, you could issue a coupon that is normally 20%-off (for most stores, or online) but that the location alert for a specific store said 'Get 50% Off at this store'. When the customer comes in to have their Pass scanned & activated, your server will then know the customer's location and can apply the 50% reduction.

Keep track of time since last attempt of ______

I have a game where users can do a certain activity once per hour. How can I make sure it's been an hour since the last time they attempted something without them just changing their devices current time in settings?
Also, if I wanted to prevent the user from just deleting the app and re-installing it so they could constantly keep trying without having to wait to full hour is there any way I can store data on the device even after an app delete or would that have to be a server thing?
If I don't have a server can anyone think of a clever way to do this via Free in-app purchases or something?
The only way to persist data in a way that survives app reinstalls is to save it to the keychain. This works, because keychain data may be shared across multiple applications; the rest of your application's data is removed on uninstall.
If you need a reliable way to tell the current time, the device must be connected to the internet. In this case you would be able to check the current time using one of the time services through the NTP.
That sounds like exactly the sort of task you would need a server for.
When the user wants to perform this limited action, have them ask the server for permission. You can log the user's ID and request time, decide if they can execute the action, then return a small success/failure message. Works if they change their clock, works if they log in from a different device, works if they wipe the device data.

Storing usage data about iOS app against the app store guidelines?

What I would like to know is whether there is anything wrong (in terms of the law, and App Store guidelines) with storing information about your application, and broadcasting it to an online location for gathering.
Specifically, an application which would normally not connect to the internet, connecting when it starts up and storing usage information like time of day, the device ID, and how long the person uses it for.
I'm guessing this sort of behavior is fine so long as you get the users consent first?
It’s fine if you ask the user first and give him an option to turn this feature off. We were once spanked out of the App Store simply for uploading a new game high-score record without a cancel button. It’s quite a long time and the rules might have changed, but better safe then sorry and your users will like the confirmation screen, too.

Resources