ฉันได้สร้างแอปพลิเคชันตัวอย่างหนึ่งรายการซึ่งเริ่มการแจ้งเตือนในพื้นที่
เมื่อการแจ้งเตือนเริ่มทำงาน จะแสดงแบนเนอร์ในพื้นที่แจ้งเตือนในอุปกรณ์เสมอ ซึ่งฉันได้แสดงไว้ในรูปภาพแล้ว
แต่ฉันต้องการการแจ้งเตือนมากกว่านี้ และต้องการดำเนินการตามตัวเลือกที่เลือกจากการแจ้งเตือนนั้น
รหัสสำหรับการแจ้งเตือนในพื้นที่มีดังต่อไปนี้
-(IBAction)setNotification:(id)sender{
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
{
return;
}
localNotif.timeZone = [NSTimeZone defaultTimeZone];
// Get the year, month, day from the date
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSTimeZoneCalendarUnit|NSSecondCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit fromDate:[NSDate date]];
// Set the second to be zero
components.minute = components.minute + 1;
components.second = 0;
// Create the date
NSDate *date = [[NSCalendar currentCalendar] dateFromComponents:components];
NSLog(@"Fire Date :: %@",date);
localNotif.fireDate = date;
localNotif.alertBody = [NSString stringWithFormat:@"First Alarm"];
localNotif.alertAction =@"Ok";
localNotif.soundName=@"Alarm_1.mp3";
localNotif.applicationIconBadgeNumber = 1;
localNotif.alertAction = @"Application name";
localNotif.HasAction = true;
// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
ท่านใดมีช่วยบอกหน่อยนะครับ..มีผิดพลาดประการใด..
ขอบคุณล่วงหน้า.