My application uses ApplicationSignificantTimeChange method for detecting time changes from device settings. But this method is called for arrival of midnight or an update of the time by a carrier or the change to daylight savings time. Is it possible to distinguish the reason for the notification initiation ?
No, there's no way to distinguish between those, but depending on what you want to accomplish exactly - there's probably a better way to do it.
For example, if you're looking for the the next moment of the following day, you can register for the NSCalendarDayChangedNotification on iOS 7
Sadly not - there is no dictionary or information passed with this call. You will have to look to other solutions to implement what you are trying to achieve.
Related
I have to added a local notification for next 30 days(June-01-2013 t0 June-30-2013).
For Example:
I have to change the date on the "settings" to June-15-2013, and then I have to change the date to June-05-2013. The local notification not called for the (June-01 to June-15). After June-16 is working fine.
My question is
1) Any restrictions for the UILocalNotification to fire the past dates?
2) Is it possible to fire the local notification for past dates?
Please help me. Thanks in advance.
Apple docs states that
If the specified value is nil or is a date in the past, the
notification is delivered immediately.
So if you are setting the fireDate of a local notification in the past the notification will be fired immediately.
Also your case I think is a special one because you are manually change the device date settings. The date settings may be changed when the time zone is changed but your case is different, you are not changing the time zone, you just change the date and I think the local notifications before (in the past) your new date are ignored.
Well, this is one of the situation i had faced when cam testing of robustness of the app. My app was also issuing notification for future dates. All goes well, if user does not change the date. But as part of testing, changing date to future and then past makes disables some notification which were suppose to appear.
The way i workaround this situation was responding to following call back in application Delegate
-(void)applicationSignificantTimeChange:(UIApplication *)application
Here i re-issued all the notifications as per required from the current date. That did the trick in my case. It's a heavy solution as all notifications has to be deleted and re-issued, but did the required for me.
There is one more case where you may required to re-Sync the notification. User may had also changed the date, when app is closed. For this, i made the application to reSync the notification everytime it launches. You can optimize this approach, by checking if there is significant change in date or not.
I'm currently working on a new game for iOS using Cocos2D. The game needs to advance states after x amount of time since the first launch. So for example:
State - Time
initial launch
24hrs
48hrs
My first idea was to just get the data and time on first launch and save it to a file. Then I could check it ever now and again to see how much time has passed. The problem with this is I need it to be in realtime so that the changes will take effect immediately once the state is reached. It also needs to continue when the user is not using the app. The functionality I'm looking for is kind of similar to how the iOS strategy games work where you build structures that take x amount of time.
Anyway my question(s) is; is there some sort of library that can accomplish this and how can I get it to continue after the user exits the app?
It can't. There is - apart from kind of misusing video/music playing etc. no way for your app to do work while it is not running.
You have two things you can do to simulate that behavior (and I suppose the strategy games do this, too):
You can calculate at any time while a user is still running your app the points in the future when something should happen (eg a housing structure is finished). When the user leave your app, store these future times as local events - then the user will get notified that something has happened in your game (eg message "The church has been built. Do you want to go to church now?)". Pressing yes will open your app, and you can do whatever is necessary to indeed build the church. So in fact you don't do it at the time when it occurred, but when the user opens your app the next time.
Like 1, but without notification. Just remember when the user leaves the app (eg in your settings, I would use a property list; set it when the app delegate gets the appWillResignActive event), and the next time he starts do whatever would have been done in the meantime - he won't be able to tell the difference :-).
It's all about make believe here :-).
I'm developing a navigation app which uses the UIBackgroundModes=location setting and receives CLLocationManager updates via didUpdateToLocation. That works fine.
The problem is that the intervals between location updates are very hard to predict and I need to make sure the app is called something like once every few seconds to do some other (tiny) amounts of work even if the location did not change significantly.
Can I do that? Am I allowed to do that? And how can I do that?
I found a blog post, but I'm not sure if this is really the way to proceed.
Permissible background operations are pretty limited in scope. You cannot, for example, just leave an NSTimer running to perform some arbitrary code while your application is in the background - so the simple answer to your question is no, you cannot. Definitely read the Apple documentation regarding what is and isn't allowed (most of what's allowed pertains to apps that "need" specific ongoing services, like the ability to play music, or respond to location changes (GPS type apps...). You may be able to construct a viable solution by responding to location or significant location change notifications...
I want to learn how, for example, I could program a picture in Interface Builder to change between 3 pictures according to the time of day.
Or how I could program a certain UIButton to appear and disappear depending on the time of day—or even more specifically, the month of the year.
Where can i go to learn about this? And what is the formal name for this? Using time signatures? Or time stamp?
The NSDate class allows you to inspect the current time (also see Date and Time Programming Topics, and the NSTimer class allows you to schedule tasks.
i want to send a notification each day at the same time with different information. I got no problem with showing the alert when i want to. The problem is what to show. First i tried to schedule one alert every day with different information in them, but that seems really inefficient. Then i tried with
-(void)application(UIApplication*)app didReceiveLocalNotification:(UILocalNotification *)Notif{}
but found out that it runs when the application is running in foreground only.
Is there any way to provide an array or something like it with the alert and tell the alert to get its body from the array with different index for different days?
Or should i do it with some notification that can run when the app is in background mode and the alert show and make a new alert?
All information must be provided when you schedule a local notification, so no, a notification's body cannot be sourced from an array as you described. If users are likely to open your app often and you know notification content in advance, perhaps you could ensure that x notifications are always scheduled (could be achieved by inspecting UIApplication's scheduledLocalNotifications).
This solution isn't ideal though, as it relies on users opening your app on a (somewhat) regular basis. I think push notifications are probably your best bet, but that requires access to a server, etc.
Yeah push could prob be the solution. But i dont have a server for that. The users will most likeley not open it any more after they have opened it the first time to activite the local-messages. So then this isnt really possible to do without push. when i tried a for-loop to schedule 250 days with different text each day it took about 2 minutes on iphone 4 so its not duable.