我为我的应用程序上的每日本地通知编写了一个代码,该代码将在每天下午 1:00(13:00)发送。我写它的那天,代码运行良好,并且通知在下午 1:00 准确发送。由于未知原因,它仅比现在效果好,但现在不起作用,我没有收到任何通知。
(我在应用程序的注册页面中编写了代码)
编码:
import UIKit
import FirebaseAuth
import Firebase
class SignUp: UIViewController {
@IBOutlet weak var emailSignupTF: UITextField!
@IBOutlet weak var passwordSignupTF: UITextField!
@IBOutlet weak var errorLabel: UILabel!
var message = ""
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.setHidesBackButton(true, animated: true)
//First Notification//
let content = UNMutableNotificationContent()
content.title = "תזכורת"
content.body = "לא לשכוח לעדכן את מיקומך בתדריך הקרוב"
// Configure the recurring date.
var dateComponents = DateComponents()
dateComponents.calendar = Calendar.current
dateComponents.hour = 13
dateComponents.minute = 0
// Create the trigger as a repeating event.
let trigger = UNCalendarNotificationTrigger(
dateMatching: dateComponents, repeats: true)
// Create the request
let uuidString = UUID().uuidString
let request = UNNotificationRequest(identifier: uuidString,
content: content, trigger: trigger)
// Schedule the request with the system.
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.add(request) { (error) in
if error != nil {
// Handle any errors.
}
}
}