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...
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 have developed an application. My application takes feedback from users. When network is not available, then that data is saved in local db. But, once the network is available, it will sync automatically with the central database.
But, I have some problem here. If I save database & send my application to background, once the network is available, it has to automatically do this syncing with the central database. How to do that?
I am using Reachability class to check network availability.
At the present time there is no way to have your app "wake up" when the network becomes available. If the user quit your app without a network connection, you cannot do anything until they voluntarily open your app.
However, you can prompt them to do so using UILocalNotification. If your app is being quit and you have some data waiting to be uploaded, you can schedule a notification to fire in 4 hours (or whatever amount of time makes sense).
If the user opens the app before the notification time and you are able to upload the data, you can cancel the notification and no one will ever know it was scheduled.
If the user does not open the app, the notification will appear, and say something like, "You have data on your phone that you have not uploaded in a while. Connect to the Internet and launch MyAwesomeApp to sync your data."
You cannot do it on iPhone. Your app ceases to exist in a few seconds (once the app moves to the background).
I believe its 5 seconds for all apps, 10 mins for some apps that have requested for more background time.
PS: Unless, you mark your app as a navigation or a music app, which can stay on in the background, theoretically, forever. But I doubt if a feedback app can get approved on the appstore with such permissions.
Keep an additional column in your saved database which marks successful uploading of your data to your server. Set this when the data is written, but not yet uploaded. When it's successfully uploaded, clear the value. You can check this value when your app comes to the foreground, and have it upload any data that hasn't had this column cleared. While your app is running, you can set a timer for an appropriate interval to recheck reachability and if successful, attempt an upload. Only clear your flag when the data is successfully written, and make sure your server doesn't try to process a partial upload (think of someone trying to do this on a subway or train, moving in and out of connectivity).
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.
I have a location based iOS app and I want to interact with a server every x minutes.
I read this post: Send Data Every 10 minutes
But I have to send an empty header to my server even if there is no location update for a while because I have to read any pending commands from my server and it only writes back if you write first.
This has to work even if the app is running background.
What should be the best way to perform this? Using a timer?
I've already made this kind of stuff on Android but I'm a little stuck on how to do here.
Cheers,
Thierry
You can use a NSTimer when the app is running, but you can't do that when the app is in background. The iOS reference contains all the possible uses of multitasking: link
As you can see, there's a small amount of possible operations (voip, audio or location) that are able to wake up your app.
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?