In my iPhone application I want to trigger a download every monday of a week, every 10th working day of a month, every 3rd day of a month etc. I did some R & D and found that NSDate, NSDateComponents & NSCalendar classes needs to be used for this scenario. Can somebody help in the same as I am new to date & time usage.
Also by the time when trigger comes if app is not in running state or mobile is switched off.. How to handle these scenarios.
If you device is switched off / out of order / app is not running, you can not do any thing.
Apple would not allow you to launch your automatically, so the question of downloading and saving is bit far.
What you can do is, whenever your app is launched you can read from plist or userdefaults about the time ( 3rd day of month ) and compare to the last saved date, if it is one month away then it is the time to download and show a popup to do so.
Only legal way to do this is to schedule NSLocalNotification to desired date. When notification is fired up and user taps it, app would be started, and there you should start with download.
The documentation for Local Notifications: Local Notifications
You can read this: iOS timed background processing
Can go through this tutorial as well.
I have reading up as well. Something new for me as well. Best is NSLocalNotifications. Have a look at this: Reminder App
Related
I am creating my first app that lets the user set alerts for themselves and then the app would send the user a local notification on the set time. The thing that I'm having trouble with now is being able to fire the local notification on specific days of the week (for example every Mondays and Tuesdays only). All the tutorials/questions that I have come across so far (like this one) have only been about scheduling the notification everyday/everyweek. The desired result that I'm trying to achieve is sort of like the iPhone's built in alarm system, where you can set an alarm to fire only on certain days of the week.
If I can't just set the notification.repeatInterval field, is there a way I can do what I'm trying to do? Could I possibly execute a little code at midnight that schedules the correct notifications for that day? If so, how could I do that?
Thanks in advance!
The thing that I'm having trouble with now is being able to fire the local notification on specific days of the week
In iOS 10, a UNCalendarNotificationTrigger is formed using DateComponents. This means you can specify as much or as little of the date-time in question as you wish. Thus, if you specify a specific weekday and a time (hour and minutes), and nothing else, you'll repeat at that time on that day of the week.
If you also need to repeat on a different day of the week, just make another notification.
I am creating my first app that lets the user set alerts for themselves and then the app would send the user a local notification on the set time. The thing that I'm having trouble with now is being able to fire the local notification on specific days of the week (for example every Mondays and Tuesdays only). All the tutorials/questions that I have come across so far (like this one) have only been about scheduling the notification everyday/everyweek. The desired result that I'm trying to achieve is sort of like the iPhone's built in alarm system, where you can set an alarm to fire only on certain days of the week.
If I can't just set the notification.repeatInterval field, is there a way I can do what I'm trying to do? Could I possibly execute a little code at midnight that schedules the correct notifications for that day? If so, how could I do that?
Thanks in advance!
The thing that I'm having trouble with now is being able to fire the local notification on specific days of the week
In iOS 10, a UNCalendarNotificationTrigger is formed using DateComponents. This means you can specify as much or as little of the date-time in question as you wish. Thus, if you specify a specific weekday and a time (hour and minutes), and nothing else, you'll repeat at that time on that day of the week.
If you also need to repeat on a different day of the week, just make another notification.
I need a piece of code for Xcode (obj-c) that runs every day at 00:00.
The reason for this is because my server updates data each new day and I would like my app to synchronize with the update.
I was thinking about doing a timer that runs every minute and checks the time (from internet, not the phones time), but it seems like there could be an more efficient way.
Help or pointers really appreciated!
Thanks
Use the calendar app on your mac. Set up a recurring event every day at 0:00. At the point where you pick the type of alert, you can select an option to open a file (as opposed to a pop-up, etc.). Pick your app as the file to be opened.
When the app becomes active, register a local notification (UILocalNotification) to trigger at midnight.
Then, you can perform the updates at the app delegate's -application:didReceiveLocalNotification:
You can then cancel the notification when the application goes to background by calling the UIApplication's method -cancelLocalNotification:
I don't think it's even required to use notification here. Notification is usually on best effort basis and doesn't guarantee the delivery. This can be done in few simple steps.
Save the lastUpdated time in your iOS app. Probably in NSUserDefaults or if you're using local database you can store it there as well.
Everytime user launches the application check how much time has elapsed since last update.
If it's more than 24 hours then make an API call to your server and check if there's any new updates available (which you can determine probably from server timestamp). Get the latest data (possibly only the delta difference in stead of everything).
Update the lastUpdated time in your iOS app.
I am a beginner and would like to make an app for iOS. I do not know where to start but I am not sure whether you can make an app that remembers you every day for a year at different times (I have time to write them in) .. ? Can you make something which can run in the background as the program 'Reminder'?
I will also have it's different in another selected city ..
Thanks
You can use local notification for that.
See this.
You can set time difference as per your requirement.
And even if your app is not running, or is not in background. It will work.
Like this,
local.fireDate = [calendar dateFromComponents:dateComps];
See this link or this , you will get the hint.
you cant run a program in the background all the time in IOS,
you can do 2 things:
you can add reminders to the calendar, so your app wont need to run all the time, only once to add it.
you can use push notifications and just send push to the users every time you want it, so all calculations will be on some php or java or any other server you want.
I want to check for update of the stored db every day or every X interval of day, how is it possible to call a method on every X interval of day? I found some code that is for the x interval of seconds, is it feasible to do by the same way? And main thing is it should run in background too. I also though of the way by storing the last updated date in database so that I retrive every time app lunch and compare with present date? Please help me by suggesting the better way.
Since you can't really run any app in background unless you are playing audio, doing something thing with the location or a re an voip client, you will need to do this when the user opens your app.
Just store the last update date in the NSUserDefault
You can not execute your application when it is closed. You can not create background applications or daemons.
Maybe running it on application start would be appropriate for you, but if you need information from the device every day, the user will have to make sure the app is open every day.