Implementing an alarm clock with uilocalnotification (Swift)

Source: Internet
Author: User

Before the project needs to achieve an alarm clock, GitHub found a half-day discovery is very old code, so prepare to write a, just recently in the study of Swift, with Swift wrote a demo put here: https://github.com/Phelthas/ Demo_alarmclock Effect Summary, Memo interface words a DatePicker plus 7 UIButton on the fix, a little bit of a problem is how to indicate which days selected, which days did not select. Here can be implemented using an array, but also can use the collection, but the simplest is to use a 16 binary number to represent (it is also on GitHub, the original use of the array to write a big lump ...) That is, with 0x111 1111来 all selected, with 0x000 0000来 means all unchecked, each 1 is selected one day. You can then use the shift operator to calculate the selected of the button to indicate whether the button has been checked for alarm or uilocalnotification. It is important to note that the uilocalnotification repetition interval is only some of the values (nscalendarunit) defined by Apple, and the interval cannot be too small (in seconds). And each app can set a maximum number of uilocalnotification (seems to be 128) so here a notification can only let the alarm clock every week x of the same time, if you want an alarm clock Monday Tuesday All rang, it is necessary to define 2 uilocalnotification, If 7 days to ring, you need 7 notice ... At present, I really do not know what other ways, if you know the students, hope that the weeks to determine the time of week, need to calculate according to Nscalendar, with Datecomponents way, It is important to note that the Apple definition of the Sunday weekday is 1 (that is, Sunday is considered the first day of the week), and we are generally accustomed to Monday as the first day of the week, so when the calculation needs to be converted, conversion method see when the demo add notification, to the notification set UserInfo, The notification identifier is set in, as a unique identifier of the notification, otherwise it cannot be canceled; Here I am the time stamp of the notification as a string to be used as a identifier of this notification

Plan to write at least one blog per month in 2016, and the first article was dragged to the end of the month ... Later fight for a little earlier!

Implementing an alarm clock with uilocalnotification (Swift)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.