环境配置:VMware+iOS 14.5+Xcode 12+SwiftUI
记录一下SwiftUI发送通知的代码(因为项目的原因所以没放全部的代码,意会一下
因为在建立项目的时候Life Cycle选的是swiftui app,所以项目中没有AppDelegate.swift文件,需要自己新建一个
//
// AppDelegate.swift
//
//
// Created by 拔牙不打麻药 on 2021/10/16.
//
import Foundation
import UIKit
import UserNotifications
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.badge,.sound], completionHandler: {
(success, error) in
if success{
print("success")
}
if error != nil{
print("error")
}
})
return true
}
}
extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter