Getting the User’s Attention While in the Background
Notifications are a way for an app that is suspended, is in the background, or is not running to get the user’s attention. Apps can use local notifications to display alerts, play sounds, badge the app’s icon, or a combination of the three. For example, an alarm clock app might use local notifications to play an alarm sound and display an alert to disable the alarm. When a notification is delivered to the user, the user must decide if the information warrants bringing the app back to the foreground. (If the app is already running in the foreground, local notifications are delivered quietly to the app and not to the user.)
To schedule the delivery of a local notification, create an instance of the UILocalNotification class, configure the notification parameters, and schedule it using the methods of the UIApplication class. The local notification object contains information about the type of notification to deliver (sound, alert, or badge) and the time (when applicable) at which to deliver it. The methods of the UIApplication class provide options for delivering notifications immediately or at the scheduled time.
Listing 3-2 shows an example that schedules a single alarm using a date and time that is set by the user. This example configures only one alarm at a time and cancels the previous alarm before scheduling a new one. (Your own apps can have no more than 128 local notifications active at any given time, any of which can be configured to repeat at a specified interval.) The alarm itself consists of an alert box and a sound file that is played if the app is not running or is in the background when the alarm fires. If the app is active and therefore running in the foreground, the app delegate’s application:didReceiveLocalNotification: method is called instead.
Listing 3-2 Scheduling an alarm notification
ได้รับความสนใจของผู้ใช้ในขณะที่ในพื้นหลังการแจ้งเตือนเป็นวิธีสำหรับ app ที่ถูกระงับ , อยู่ในพื้นหลัง , หรือไม่ทำงานที่จะได้รับความสนใจของผู้ใช้ ปพลิเคชันสามารถใช้ในการแจ้งเตือนท้องถิ่นเพื่อแสดงการแจ้งเตือน , เล่นเสียง , app ของป้ายชื่อไอคอน , หรือการรวมกันของทั้งสาม ตัวอย่างเช่น app ที่นาฬิกาปลุกจะใช้การแจ้งเตือนในท้องถิ่นเพื่อเล่นเสียงปลุกและแสดงการแจ้งเตือนการยกเลิกการแจ้งเตือน เมื่อการแจ้งเตือนจะถูกส่งไปยังผู้ใช้ ผู้ใช้จะต้องตัดสินใจว่า ถ้า ข้อมูลสิทธินำ app ไปเบื้องหน้า ( ถ้า app ที่ใช้ในเบื้องหน้า , การแจ้งเตือนในท้องถิ่นจะถูกส่งอย่างเงียบๆ app และไม่ให้ผู้ใช้ )ตารางการส่งการแจ้งเตือนในท้องถิ่นสร้างอินสแตนซ์ของ uilocalnotification คลาส ปรับแต่งพารามิเตอร์และการแจ้งเตือน , ตารางเวลาการใช้วิธีการของ uiapplication ชั้นเรียน แจ้งท้องถิ่นวัตถุประกอบด้วยข้อมูลเกี่ยวกับประเภทของการแจ้งเตือนส่งเสียงเตือนหรือป้าย ) และเวลา ( ที่สามารถใช้ได้ ) ที่ให้มัน วิธีการของ uiapplication คลาสให้ตัวเลือกสำหรับการแจ้งเตือนทันทีหรือตามกำหนดเวลาเดิมรายการตัวอย่างที่ 3-2 แสดงตารางเวลาปลุกเดียวโดยใช้วันที่และเวลาที่กำหนดโดยผู้ใช้ ตัวอย่างนี้ลดต้นทุนเพียงหนึ่งสัญญาณที่เวลาและยกเลิกการเตือนก่อนหน้านี้ก่อนที่จะจัดตารางใหม่ ( ปพลิเคชันของคุณเองสามารถมีได้ไม่เกิน 128 แจ้งท้องถิ่นที่ใช้งาน ณเวลาใด ๆ ซึ่งสามารถปรับแต่งได้อีกในช่วง ระบุ ) ปลุกเองประกอบด้วยกล่องการแจ้งเตือน และ ไฟล์เสียงที่เล่นถ้า app ที่ไม่ได้ใช้หรือในพื้นหลังเมื่อสัญญาณเตือนไฟไหม้ ถ้า app ที่ใช้งานอยู่และดังนั้นจึงทำงานในเบื้องหน้า , app แทนของโปรแกรม : didreceivelocalnotification : วิธีเรียกแทนการตั้งเวลาแจ้งเตือนรายการที่ 3-2
การแปล กรุณารอสักครู่..
