I'm making an app that displays text from an array and I need to background refresh the text depending on the date at midnight. How can I background fetch this at exactly 12:00am so it shows the new text? I turned on background fetching on the file and it refreshes at about 2pm or 3pm the next day but I don't know the code to do this at exactly midnight, I'm new to all this.
Related
We have a registration form kind of screen where user enters some sensitive data, we want to delete the already entered data if the app is in background for more than 20 mins.
We do not want to keep the data forever when app is background.
Any ideas what is the best way to achieve this?
Get and save the time when the app goes into background.
Get and save the time when the app goes into foreground again.
Calculate the difference and take the appropriate action.
In an iOS app I have a view with a UIDatePicker which only selects time (hour, minute, and am/pm). Then based upon the time of the UIDatePicker, sets an NSTimer. This timer is supposed to launch daily at the time specified on the UIDatePicker. Is there anyway to set up an NSTimer with a specified hour, minute, then either am or pm without having to take the date into consideration? Being able to do this would allow me to remove a huge amount of conditional statements regarding month's, day's and years.
If this isn't possible is there a recommended approach?
Thanks!
Check out UILocalNotification:
https://developer.apple.com/library/ios/documentation/iPhone/Reference/UILocalNotification_Class/
How can I make something happen in a specific hour in the Date Picker?
I am just learning Swift I would appreciate any orientation. Thank you!
I can grab the time the user select when he click a button, but how can I make something happen when we arrive to that time and the app is active?
(I am not looking for localNotifications, I want something happen WHEN THAT APP IS ACTIVE)
I put this inside ViewController.swift > class ViewControler: UIViewController:
let now = NSDate()
#IBAction func button(sender: AnyObject) {
// grab the selected date from the date picker
let wakeUpTime = datePicker.date
}
If you want something to happen when the app is active, do the following:
Grab the user-selected date from the picker. Save it to user
defaults.
Calculate the number of seconds from now until the user-specified
date:
let seconds = userDate.timeIntervalSinceReferenceDate() -
NSDate().timeIntervalSinceReferenceDate()
Create a one-shot timer that fires in that many seconds.
Done.
If you want your app to work correctly if the user switches your app to the background and then back, kill the timer on the way to the background.
When you get launched or return to the foreground, read the saved date, and repeat the above. (After checking to see if the saved date has already passed.)
How to calculate the last time app is active
Using timers and last touch object
I want my app to be quickly accessible between pre-set hours, say 9am to 5am Mon-Fri from the locked screen so swiping right on the notification will take you directly to the app. Is there a way of making this notification "shortcut" always present on the locked screen during those pre-specified times?
Or if not, is there a way around it? e.g. make the notification pop-up 1 minute after the person locks their screen everytime?
Thanks