ios 10 本地发送通知填坑

ios到10以后本地通知改的比以前复杂,但是参考文档还是可以比较轻松地写出来,新使用的是UserNotifications,import即可。

 首先是注册过程,这个需要获得用户许可,就是大多数app一开始的是否允许发送通知,如果点了否...那没办法了,尝试远程

let center = UNUserNotificationCenter.current()
    center.delegate = self
    center.requestAuthorization(options: [.alert, .badge, .sound]) { (resulet, error) in
        if resulet {
            print("register notification success")
        }
        else {
            print("register notification fail error.localizedDescription:\(error?.localizedDescription)")
        }
    }
实现自己的通知,因需求而异,自定义即可,相比低版本复杂了不少,吐槽

最后向通知中心加入通知,若考虑多个通知,request的确定identifier必须一对一,如果只使用一个,则只会发送最近的那一条,大坑。

猜你喜欢

转载自blog.csdn.net/PrecipitantPan/article/details/81226080