Swift 3: UIButton re-enables after midnight - swift

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! :)

Related

How do I show all calendar events in "Today View" in iOS 9?

This is a duplicate of the question at the following address, because the answer provided there is incorrect, and I don't have the reputation points to comment or otherwise correct it:
https://apple.stackexchange.com/questions/206921/how-do-i-show-all-calendar-events-in-today-view-in-ios-9/206937#206937
The answer provided by dordio does not actually answer the question.
I want to give credit to user "BMANN2" on Reddit, from this thread:
https://m.reddit.com/r/apple/comments/3lameq/ios_9_calendar_widget_not_showing_whole_day/
Since I can only post two URLs with my rep, here's a very shortened, simplified version of his response without his links to images:
1) Open calendar app.
2) Once in Calendar, switch to a different viewing mode, then pull down the NC. It should switch the Today widget view to match what you see in Calendar.
For his full answer, look for the post that starts with "Ok I seem to have found out how to do it, it is somewhat like what was mentioned by Vanitas1440."
This seems to only work if you switch viewing modes then pull down the NC without switching to another app entirely in between. If you come back to Calendar from another app, then pull down the NC, the change doesn't take effect.
The first time I tried this method, it didn't work, because I went to the calendar app, and the view I wanted (list view) was already onscreen, so I pulled down the NC, and nothing happened.
However, I then switched the view in calendar to the layered day view, then pulled down NC and "Today" updated to the new view.... so any view can be used.
Once I changed the view back to the one I actually wanted and pulled down the NC again, now my Today view widget is set to the proper one.
I hope this helps!
If anyone wants to merge this into the other thread, feel free.
It's already answered in the question:
1) Open calendar app.
2) Once in Calendar, switch to a different viewing mode, then pull down the NC. It should switch the Today widget view to match what you see in Calendar.

Objective-C: Trigger method with computer keyboard stroke

Sorry if the questions is asked/answered already, or if my title is poorly worded.
I am currently writing an iPhone app, and have considered a useful tool for debugging. I would like to write a method that just prints variables and other info that I want. That part is simple and all, but I want this to be called by keystroke.
For now I have been just adding NSLog()'s to viewDidLoad or to other button methods to check if my variables are being set properly, but it's becoming tedious and the code is long so I tend to forget about some and spend a lot of time looking for them haha.
I just want one method that I can go to to write my NSLog()'s, and have that method call whenever I hit 'space' or something of that sort.
Can this be done?
Thanks!
-SF
It's pretty hard to do, you need to have a hidden text field that you keep in focus, hide the software keyboard for it, then listen on its delegate methods for changing text.
An alternative would trigger the code inside applicationWillResignActive: which gets called on application hiding, notification center showing, or double home press.

Custom PickerView froze up (With sample project)

Background: I have been wanting a PickerView that is exactly matches that of Safari. I looked through many Gits and found none that work quite as exactly. I decided to build my own. It is complete now, but there is a bug that would not go away.
Problem: If you run the sample project you will be greeted with 2 text fields.
Tap on one of the textfields - it brings up the BTPickerView. Everything works just as you would expect.
Choose the fourth choice, then press done.
Tap on the same textfield. This time, the debug log will show you that you have executed an infinite loop, which freezes the app.
Question: What did I do to cause it? And how do I fix it?
I have tried everything to boil it down. It comes down to this and I could not go any further. Please advise.
Edit: Here is the sample code you can download in case anyone missed the blue link above.
The issue seems to be with the constraints in BTPickerLabel. If you temporarily disable the constraints from BTPickerLabel, code works fine. Enforcing constraint might trigger the reloading of entire picker view infinitely. I hope it should help you to fix the problem.

Titanium iOS - agcalendar monthview won't update view

After a new event is added... or an event is deleted I have to hit the next month button then go back to the current month for it to update the calendar properly. I got around this by using the calendarView.selectTodaysDate();. This seems to work for the most part on added events, however it doesn't work when an event is deleted
this is the module I'm using for the monthView:
Module Link
I'm thinking at this point maybe I could make the view refresh, but am not 100% sure how Titanium does that.
Any help would be sincerely appreciated!

Providing un-intrusive messages on an iPhone

This is kind of a silly question, but I cannot find the answer as I don't know the terms with which to search for it.
I am looking for a simple way of giving a 'status' message like 'Data updated' to the user without necessarily interrupting what he/she is doing (but have a option I guess in some instances to tab it an perform an action).
For example; some Apps give a rounded square semi-transparent with 'Lock screen/rotation' when an iPhone is rotated, I am look for something similar (or like the square box 'Build Complete in Xcode 4').
Is there an easy way of doing this?
Thanks a million in advance!
https://github.com/myell0w/MTStatusBarOverlay
MTStatusBarOverlay adds very subtle text to the phone's status bar. If you're looking for something a little more noticiable, try:
https://github.com/jdg/MBProgressHUD
As #kubi has pointed out, MTStatusBarOverlay is a good one, and I've passed Apple reviewer inspection with it. However I just found something that looks fraking awesome...
Tweetbot-Like Alert Panels (Blog), and the repository is MKInfoPanelDemo at Github.
Create a view that shows your message nicely, add it to the window, and start a UIView animation which makes it fade away. In the animation ended handler (delegate or block) remove the view.