One of my apps uses a database that synch's online with another. The online data update pretty frequently, so I'd like to remind users to update their local data every 24 hours after they open the app, not while it's closed.
Is it easier to do this with NSUserDefaults, or is it possible to schedule a Local Notification to execute only if the application is opened?
Thanks
Use NSUserDefaults.
Notifications are specifically designed to work while the app is not running :)
When the app is started, check the time of the last update and then start an NSTimer to fire at the correct time and tell the user to update.
However, is this good ui practice?
Surely it's better for your app to update itself in the background without interrupting the user?
Related
I am creating an idle game (user is rewarded for offline time with ressources). For that calculation I will need the elapsed time since the app was closed.
My first idea was to save the current time when the app is closed and read the current time when the app is opened. But what if a malicious user changes the system time between those actions? The user could get as many ressources as he wants with this trick.
My solution would be to consult a time server to get its current time when closing and opening the app. But this would mean the app would need to be always online, which I am trying to avoid.
Is there any other way I could use to accomplish this?
I don't think it means that the app always needs to be online. You just take the server time when the user closes the app and you take the time when the user opens the app again. You then subtract the first from the latter and then you have the offline time. Assuming of course that you save the "last_closed" time in a database of some sort.
When you are online you read correct time from an api which shows greenwich time not from user's device; so that you always have correct time.
I am building an app that requires core date to update every Sunday. e.g. it will save "thisWeek"'s data to "lastWeek" every beginning of a new week, and reset "thisWeek" to let user input new data for new week.
My question is how to achieve this even if user is not running the app at all?
Use UILocalNotification with repeatInterval property which reschedule the notification with calendar interval. I suggest to go through following Apple iOS guidelines. Bottom line, your app will be open when notification will occur.
UILocalNotification
Just do the archiving if necessary whenever the user starts the app. If your data is timestamped this should be simple and there is no requirement for the phone to even be switched on.
This isn't possible. Your application cannot execute code unless the user has launched it. You could provide a local notification to prompt the user to reopen the app, however this is a sub-optimal solution.
A better solution would be to timestamp your data and then whenever the user opens the app, regardless of when, you can process all of the data and move it where it needs to go.
Is it possible to have an App (running iOS4 on hardware supporting multi-tasking) which starts on iPhone startup and then regularly checks for online updates (every 15 minutes) and then refresh the badge, so the user can see how many unread items there are with-out having a push-server?
I was hoping this would be possible with iOS4 Programming Guide seems to suggest it is only possible to to this regarding Locations tracking, VoIP and playing background audio. There is also the possibility to do local-push notifications, but I don't see to find how to trigger a specific function that way.
Thanks in advance for any help!
edit:
Just having read a bit more, if the application is in the background/inactive state, and I son want to update the badge-number without displaying a message, is there an action triggered like didReceiveLocalNotification? There must be a way to schedule something on a regular basis (like email checking) without having to implement a full server-push-nitification system!
Is it possible to have an App ... which starts on iPhone startup and then regularly checks for online updates (every 15 minutes) and then refresh the badge
As you already figured out, the answer is no.
I have an app that requires me to take an action after some period of time. For example, if an user hasn't been inside the app in few weeks, when the user eventually starts the app, I have to ask them to put in a special code that was given to them when they installed this app. (this is an in-house app and i am being required to do this due to security concerns)
I am using the [NSDate date] method to retrieve the date when the user logs in and save it into a database. I compare this saved date next time they open up the app and see how long its been since their last login. The problem is that [NSDate date] gives the time that is effected by the time settings that can be changed manually by the user in the native settings app. As you can probably tell, this causes lots of problems to my situation. If the user is suppose to be put the special code after 3 weeks of inactivity, he can cause the app to show this screen by modifying the time in the native settings app or worse, get away from it by setting the time to a previous date that will be within 3 weeks of his activity.
Is there a way to get the "system time" instead of the "user time"? I have looked into mach_absolute_time() but this gets reset after restart of the device. Since the time of inactivity I will be comparing against is pretty large, chances are device would have been restarted by then. I also thought of using network connection to get the time from servers outside the app, but lots of users won't have access to wifi where they use their iPads. That will be my last resort solution if i can't find anything else. Because of their location during usage, I am trying to use everything on the device itself.
Am I overlooking something simple here? this seems too simple of a problem to not have an answer. Please guide me toward the right direction. Thank you in advance.
Why not query a remote server for the time - lots of NTP servers about or just make a simple HTTP request to a php script on your own server. Of course if your app is likely never to be connected to the internet that could be a problem, but once you have a 3rd party time its quite easy to guess if the user has been playing with the clock.
If this is an inhouse app (so you aren't constrained by Apples approval process), you could mark your app as doing some background stuff (voip or receiving location updates), so that the app will always be active and you'd be able to update some sort of an "unused" counter. Voip app will even be restarted by the OS after device reboot.
But of course it'll drain the battery somewhat.
Either: make having the actual time an essential feature of your app. This way the users will have a need to keep the time of the device current and can't go back three weeks
Or: mark the code as expired and save this information before the app informs the user. This will stop most user from setting the time back. Most will try once or twice, see that the app stays disabled and will give up.
You can also save the timestamp of the last successful execution and if that is more than a reasonable time frame in the future (remember summer/winter time) then consider it a "hack attempt". Put a CRC check (or whatever obscure idea you come up with) on that timestamp and save it too and you will stop a large number of script kiddies.
You can never stop the diehard hacker who search actively for every trick you might have put into the app. Just focus on the "average" user.
I want to ask a question about the iPhone application. I am writing a program which can upload some information to a server. However, the user has to click a button before the upload. Therefore, is it possible for the application to upload the data to server regularly after the user only click one time of the button?
It means that the app will upload the data at 12:00 p.m, 12:00 am .... Thank you.
It is possible if and only if your app run all the time. Otherwise, if users quit your app then you cannot set and run any code inside your app. You also cannot set any timer inside iphone to run your app.
So, if the user open your app in the time. Then you can use NSTimer to schedule the time to upload your data. If user quit, you stored the last time you upload data, then when user open your app again, you check for the last time uploading and if it is too old, you upload data again. + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds invocation:(NSInvocation *)invocation repeats:(BOOL)repeats
More here
Please correct me if I'm wrong, but I do not believe this is possible using the current official SDK.
I dont know why you need to send the data to webserver regularly.
Suppose if you are not running the application for 7 days, the data is not gonna change in iPhone den whats the reason to re upload the unchanged data.
So suggest you to upload at the time of exiting the application or at the time of starting the application What ever you prefers.
Happy Coding...