Fire action at specific date and time iPhone - iphone

in my Core Data model, I have an entity which has got a date attribute. For example, I'll set this date to 10/07/2011 4:00pm and I want to fire an action when current date will pass the saved date by one minute.
A local notification will be fired but I also want to fire another method to change another entity attribute's value. Is it possible to do something like this?
I've also thought to NSTimer but I've never used them... And a last question: will this action fire always even is app isn't in background or foreground?
Thank you so much!
Matteo

You can't fire an action while running in background mode other than through local notifications.
To check if the date condition has been met while running in foreground, NSTimer is the way to go.

Try to check Local notifications

Related

local scheduled notification without clicking a button (automatically)

I am making an app that gets data (that has a name, time and date of the event) from the local database and use that to create scheduled notification. I wanted to make the notification work without having to click on a button.
Currently, this is working with a button in the screen, but I tried putting it in the initState method, and it did not work.
Any help is greatly appreciated.

Swift 3: UIButton re-enables after midnight

I have a button which disables after it is pressed. I need To work out how to get the button re-enable after midnight, or the next day.
So I think I need the button to set the date in a variable after it is pressed. Then an if statement which enables the button if the variable does not match today's date.
Would that be the best way to handle it? Can anyone offer any rough code advice, or possibly advice of an easier way to handle enabling a button after midnight?
Thanks
Then an if statement which enables the button if the variable does not match today's date.
But the question is, an if statement where? Your code can only run if something makes it run. If your app is just sitting there, midnight can come and go and your button won't be enabled because the code that looks to see if it's a different day from the day you saved is not running.
The solution:
Register to be notified by the system when the day changes.
Woow finally some nice question... it's definitely possible... you can check this beautiful documentation by apple:
https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
Basically you have 2 or more solutions, just 2 comes to my mind right now:
1.) Use UserDefaults or CoreData (Userdefaults for one property is more acceptable I guess
2.) Run backgroundTask as mentioned above..
The first one is very basic solution... you get the date when the button was tapped and if the day is equal to the day you entered the screen later, you keep the button disabled, else you unlock the button and store again the date into the user defaults, this seems to me a little piggy if you ask me..
The second one is much more elegant, in a nutshell... You setup button with some actions and the last thing is disabling it. Then, you setup background Task that every next day the button becomes enabled again...
I am pretty sure you will find the codes somewhere else here, maybe you will find the first algorithm more useful for you..
Anyway wish you best luck and happy coding! :)

Detect "Close" button in local notification

I am programming an app where the user sets a kind of daily alarm where the application shows certain information every day at the same time. I'm try to make this feature with local notifications. My problem is when the user press the close button of the local notification received, because there is no way to detect this event. I have been searching and seems no solution. I just post this question to be sure there is no solution about the "Close" event.
Thank you
did you try do add a repeating notification?
check this property: notif.repeatInterval
you can add a repeating notification, that fires every hour or day or ...

How to fire Local notification with custom view instead of default pop up according to set timer in iphone

Is there any standard step by step way to use the local notification in iPhone application.
I have never worked for local notification.
I am interested to use this to create a fake call.
So, i am interested to set the timer in the local notification & as per the timer i have to set the local notification with custom view instead of the default pop up of notification.
Please suggest me the standard way to deal with local notification.
Every type of suggestions & links are appreciable in advance.
Thanks.
You can't customize the local notification alert. I have also once searched for this. Alternatively I ended with showing the custom alert when the user accepts the local notification (similar to 2Do:Task done in style application).

How to list only some events in my iphone table view?

I have an application uses Events framework to add events to calendar and it works fine. The user will add his events to fire at a certain time with the standard events UI.
Then I want to read only the events created using this application and not to list all the events on the iPhone calendar application. Any help?
when cration an event, try to flag or tag them. Then, in tableView data source, chack your flags/tags
EKEvent object contains eventIdentifier property. I have not used it ever, so not having much idea about this. But still I think this is what you are looking for.
In case you cannot find a good way to flag the items, you could save a unique identifier of all events that are created, when they are created, and then compare this list of events to the ones loaded from the calendar.