|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- //
- // UserNotificationManager.swift
- // im-client-ios
- //
- // Created by 北京居家科技有限公司 on 2022/2/24.
- //
-
- import Foundation
- import UserNotifications
- import CoreLocation
-
- class UserNotificationManager{
- static let instance = UserNotificationManager()
- func requestAuthorization(){
- UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.sound,.badge]) { (success, error) in
- if let error = error {
- print("something goes wrong,\(error) ")
- }else{
- print("success")
- }
- }
- }
-
- func sendNotification(title: String!, body: String!){
- let content = UNMutableNotificationContent()
- content.title = title
- content.body = body
- content.sound = .default
-
- //5秒之后触发通知
- // let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
-
- //17:05触发通知
- // var date = DateComponents()
- // date.hour = 17 /* 使用24小时制*/
- // date.minute = 18
- //
- // let trigger = UNCalendarNotificationTrigger(dateMatching: date, repeats: false)
-
-
- let coordinate = CLLocationCoordinate2D(
- latitude: 50,
- longitude: 60)
- let region = CLCircularRegion(
- center: coordinate,
- radius: 200,
- identifier: "")
- region.notifyOnEntry = true
- region.notifyOnExit = true
- let trigger = UNLocationNotificationTrigger(region: region, repeats: true)
-
- let request = UNNotificationRequest(identifier: "notification", content: content, trigger: trigger)
- UNUserNotificationCenter.current().add(request)
- }
-
- func removeNotification(){
- UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
- UNUserNotificationCenter.current().removeAllDeliveredNotifications()
- }
- }
|