I am trying attach image to notification in iOS module of Libgdx project. But while initializing UNNotificationAttachment i am getting following error
2020-08-26 08:09:56.711 IOSLauncher[29001:1089461] -[NSURL init] called; this results in an NSURL instance with an empty URL string. Please use one of the documented NSURL initialization methods instead (initWithString:, initFileURLWithPath:, etc.). This message shown only once.
2020-08-26 08:10:03.864 IOSLauncher[29001:1089573] XPC connection interrupted
SLF4J: Failed to load class "org.slf4j.impl.StaticMDCBinder".
SLF4J: Defaulting to no-operation MDCAdapter implementation.
SLF4J: See http://www.slf4j.org/codes.html#no_static_mdc_binder for further details.
Exception in thread "main" java.lang.RuntimeException: Objective-C initialization method returned nil
at org.robovm.objc.ObjCObject.initObject(ObjCObject.java:108)
at org.robovm.objc.ObjCObject.<init>(ObjCObject.java:97)
at org.robovm.apple.foundation.NSObject.<init>(NSObject.java:136)
at org.robovm.apple.usernotifications.UNNotificationAttachment.<init>(UNNotificationAttachment.java:54)
at org.robovm.apple.usernotifications.UNNotificationAttachment.<init>(UNNotificationAttachment.java:51)
at ua.gram.munhauzen.NotificationDelegate.scheduleNotification(NotificationDelegate.java:109)
at ua.gram.munhauzen.IOSLauncher.showNotificaiton(IOSLauncher.java:414)
at ua.gram.munhauzen.IOSLauncher.willResignActive(IOSLauncher.java:644)
at com.badlogic.gdx.backends.iosrobovm.IOSApplication$Delegate.$cb$applicationWillResignActive$(IOSApplication.java)
at org.robovm.apple.uikit.UIApplication.main(Native Method)
at org.robovm.apple.uikit.UIApplication.main(UIApplication.java:446)
at ua.gram.munhauzen.IOSLauncher.main(IOSLauncher.java:288)
As the error line 1 clearly states that: "this results in an NSURL instance with an empty URL string. Please use one of the documented NSURL initialization methods instead (initWithString:, initFileURLWithPath:, etc.)" You might be having problem initializing NSURL.
Below is an working example of UNNotificationAttachment:
UNNotificationAttachment attachment = null;
File file = new File(filePath);
URL url = null;
try {
url = file.toURI().toURL();
} catch (MalformedURLException e) {
System.out.println("URL--------------------->" + url);
}
if (url != null) {
NSURL nsURL = new NSURL(url);
System.out.println("NSURL -------------" + nsURL);
try {
attachment = new UNNotificationAttachment("image", nsURL, null);
} catch (NSErrorException e) {
System.out.println("Attachment Error:----------------->" + e);
}
System.out.println("Attachment : " + attachment);
}