I would like to get a clarification on notifying the timezone change in an app.
Scenario 1: When the user changes the timezone manually from the iPhone settings. I guess in this case, following post will workout.
Notify app when iPad date time settings changed
Scenario 2: If the app is in foreground and the user is travelling to a different timezone from the timezone set in phone settings. In this case, is there any way that the app can be notified about the change of timezone? That means when ever the location changes to a different timezone, will it be possible to notify the app about change in timezone.
I have seen one more way the timezone change can be notified, which is given as following.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(timeZoneChanged) name: NSSystemTimeZoneDidChangeNotification object:nil];
Can anyone give the best way of notifying the timezone change based on scenario 2.
You can handle both notifications by letting them call the same method. All you need to know is that any times that you are displaying may have to change; in the rare case that you would display the user's time zone, that needs changing as well. Both notifications will be rare, so it would be easiest to just redisplay everything.
You might also consider looking at nextDaylightSavingTimeTransition; if there's anything that needs changing. For example if I set an alarm to 8am and you notice that daylight saving time changes between now and the alarm, you could ask if you want the alarm at 8am tomorrow, or 24 hours after 8am, today.
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.
May be I am asking a stupid question here.
I recently noticed an UIApplication delegate method
- (void)applicationSignificantTimeChange:(UIApplication *)application {
}
I was wondering what will be its actual use? Do we need to handle this. Can anyone explain a scenario that can happen in an iOS application and we need to do some coding here.
My App is really sensitive to system time, that is the reason I am asking this question. After seeing this API , I have a feeling that I am missing something here to handle.
I am just curious to know... :)
Thanks,
Ramesh Chandran A
Per the documentation on iOS, this method is called:
Examples of significant time changes include the arrival of midnight,
an update of the time by a carrier, and the change to daylight savings
time. The delegate can implement this method to adjust any object of
the app that displays time or is sensitive to time changes. Prior to
calling this method, the app also posts a
UIApplicationSignificantTimeChange notification to give interested
objects a chance to respond to the change. If your app is currently
suspended, this message is queued until your app returns to the
foreground, at which point it is delivered. If multiple time changes
occur, only the most recent one is delivered.
Examples of when this should be used include:
If your app has repeating scheduled events, such as a local notification that now is past, and your app should reschedule the next notification (like daily reminders).
If your app displays data in time ago that needs to be correct, even if the user sets a bad time (for example a medical app that shows your current glucose reading or similar). If a glucose monitor showed an old glucose value as the users current glucose value for instance, the user could make the wrong decision and get hurt.
How you respond to this event depends on your application. You could for instance, read UTC from a server to see if the phone's UTC is correct within some margin, and take appropriate action, such as warning the user, or updating an internal offset between actual UTC and phone UTC.
Hope that helps.
-applicationSignificantTimeChange: is roughly equivalent to the UIApplicationSignificantTimeChangeNotification notification.
I have a custom date picker control that highlights the today date. Subscribing to this notification allows it to change its highlight at midnight, or if the user messes with the time setting manually.
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.
In an iOS app, is there any method to get notified either user changed the date or time setting.
Actually in an app we want to know the time difference between the two app sessions. It can be done by saving the time when user closed the app and when user restart again. But what if user change the time setting in between.
Can we get noticed at the starting of the game whether user changed the time/date setting.
Any suggestions would be of great help.
UIApplicationSignificantTimeChangeNotification is what you're looking for. But there's another case where date may change, for example when user changes time zone. In this case you need to observe NSSystemTimeZoneDidChangeNotification.
I believe that this is what applicationSignificantTimeChange: (on the app delegate) and the UIApplicationSignificantTimeChangeNotification notification is used for (though the case where the user manually changes their time is not listed as an example)
will UIApplicationSignificantTimeChangeNotification work if user set automatically setting clock in iOS's General setting, and the clock of the device changes because of the carrier time change?
Is there any other way to get notified when system clock changes while app is running.
The UIApplicationSignificantTimeChangeNotification notification is sent at midnight or anytime the device's time changes (such as daylight savings, the user changing the time, timezone changes, etc.). I don't have direct knowledge of whether changes in time from the carrier will trigger this notification but given the other events, I'd be surprised if such a change didn't trigger the notification.
Documentation says yes, it is called due to carrier time changes.
"Posted when there is a significant change in time, for example, change to a new day (midnight), carrier time update, and change to or from daylight savings time.
This notification does not contain a userInfo dictionary"