Мне нужно прикрепить изображение URL к моему push-уведомлению, которое я отправляю с моей консоли php.Для заголовка и тела никаких проблем, но я не могу показать изображение.Но я не хочу использовать класс Notification Service, потому что я делаю все в этом классе.Как я могу это сделать?Ниже часть AppDelegate.Спасибо за все советы.
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
//OTHER CODE
struct Root : Codable {
let title:String
let message:String
let image:String
}
let state = UIApplication.shared.applicationState
if state == .background || state == .inactive{
if let str = userInfo["data"] as? String {
let data = userInfo["data"] as? NSString
print("DATA: \n\(data!)\n")
let res = try? JSONDecoder().decode(Root.self,from:str.data(using:.utf8)!)
let stringImage:String = res!.image
if res!.image == "" {
let center = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
content.title = "\(res!.title)"
content.body = "\(res!.message)"
content.sound = .default
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: "t", content: content, trigger: trigger)
center.add(request, withCompletionHandler: nil)
} else if res!.image == stringImage {
let center = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
let imageURL = URL(string: "\(res!.image)")! //this is my url that i send from console: http://demo-lab.it/app-php/okkey/push/upload/offerta_1.png
print("URL IMAGE: \(imageURL)")
content.title = "\(res!.title)"
content.body = "\(res!.message)"
//content.attachments = [attachment] //HELP ME.
content.sound = .default
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: "t", content: content, trigger: trigger)
center.add(request, withCompletionHandler: nil)
}
}
}else if state == .active {
let str = userInfo["data"] as? String
let res = try? JSONDecoder().decode(Root.self,from: str!.data(using:.utf8)!)
self.showAlertAppDelegate(title: "\(res!.title)", message: "\(res!.message)", imageName: "\(res!.image)", buttonTitle: "OK", window: self.window!)
}