Cuando le doy tap a la notificación para expander, me aparece arriba lo que es el titulo y el mensaje, en la parte de abajo la imagen. Lo que estoy buscando es cambiar ese orden, que la imagen este arriba y el body abajo.
- Aclaro que esto lo estoy haciendo todo por fuera del ViewController, desde el AppDelegade se esta utilizando firebase para obtener esta data y así crear la notificación localmente en otra clase.
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
registerDataNotification(didReceiveRemoteNotification: userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}
- Esto es lo que estoy obteniendo por ahora:
- El objetivo es llegar a esto:
- El código que tengo es el siguiente:
fileprivate func triggerNotification(image: String?, id: String?, title: String?, body: String?, visualizationMode: VisualizationMode){
let content = UNMutableNotificationContent()
content.title = title!
content.body = body!
content.badge = 2
content.sound = UNNotificationSound.default()
if image == nil || image?.count==0 {
notifyUser(id, content)
}else{
do {
let fileUrl = URL(string: image!)
let data = try Data(contentsOf: fileUrl!)
var uIImage = UIImage(data: data)
uIImage = visualizationMode.rawValue.contains("Text") ? uIImage!.resized(toWidth: uIImage!.size.width) : uIImage
if let attachment = UNNotificationAttachment.create(identifier: id!, image: uIImage!, options: nil) {
content.attachments = [attachment]
}
notifyUser(id, content)
}
catch{
print(error.localizedDescription)
notifyUser(id, content)
}
}
}
fileprivate func notifyUser(_ id: String?, _ content: UNMutableNotificationContent) {
let masivNotification = MasivNotification(didReceiveRemoteNotification: jsonCleanUserInfo)
eventService.registerEvent(masivNotification: masivNotification, masivEventType: MasivEventType.Received, token: token,
country: country, masivPlatform: masivPlatform.Ios, externalAppId: externalAppId)
let request = UNNotificationRequest.init(identifier: (id)!, content: content, trigger: nil)
UNUserNotificationCenter.current().add(request)
}
extension UNNotificationAttachment {
static func create(identifier: String, image: UIImage, options: [NSObject : AnyObject]?) -> UNNotificationAttachment? {
let fileManager = FileManager.default
let tmpSubFolderName = ProcessInfo.processInfo.globallyUniqueString
let tmpSubFolderURL = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(tmpSubFolderName, isDirectory: true)
do {
try fileManager.createDirectory(at: tmpSubFolderURL, withIntermediateDirectories: true, attributes: nil)
let imageFileIdentifier = identifier+".png"
let fileURL = tmpSubFolderURL.appendingPathComponent(imageFileIdentifier)
let imageData = UIImagePNGRepresentation(image)
try imageData?.write(to: fileURL)
let imageAttachment = try UNNotificationAttachment.init(identifier: imageFileIdentifier, url: fileURL, options: options)
return imageAttachment
} catch {
print("error " + error.localizedDescription)
}
return nil
}
}