在 Libgdx iOS 模块中为 Rich Notification 初始化时 UNNotificationAttachment null

UNNotificationAttachment null while initalizing for Rich Notification in Libgdx iOS module

我正在尝试将图像添加到 LibGdx 项目的 iOS 模块中的通知中,为此我需要在 UNNotificationAttachment 中为图像添加 url 并将此附件添加到通知中心,但在初始化 UNNotificationAttachment 时仅 return null.

 try {
            System.out.println("Attachment TryEntered--------------->");
            dir = NSFileManager.getDefaultManager().getURLsForDirectory(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask).first();

            String tmpSubFolderName = NSProcessInfo.getSharedProcessInfo().getGloballyUniqueString();
            NSURL tmpSubFolderURL = new NSURL().newURLByAppendingPathComponent(tmpSubFolderName,false);

            java.lang.String imageURL =  dir.getPath()+"/.Munchausen/en.munchausen.fingertipsandcompany.any/expansion/chapter/icon_a1.png";
            System.out.println("Img url = "+imageURL);


            NSDictionary<?,?> dictionary1 = new NSDictionary<>();

//            attachment = new UNNotificationAttachment("image", new NSURL("https://png.pngtree.com/element_our/20190528/ourmid/pngtree-small-url-icon-opened-on-the-computer-image_1132275.jpg"),dictionary1 );
            attachment = new UNNotificationAttachment("image", new NSURL(imageURL), dictionary1);

        }catch (Exception e){
            System.out.println("Attachment Error--------------->"+e);
        }

-------------------- --------------********* **

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 "Thread-5" 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:156)
    at ua.gram.munhauzen.NotificationDelegate.invoke(NotificationDelegate.java:65)
    at ua.gram.munhauzen.NotificationDelegate.invoke(NotificationDelegate.java:58)
    at org.robovm.apple.usernotifications.UNUserNotificationCenter$$BlockMarshaler0.invoked(Unknown Source)
Unhandled exception (probably in a @Callback method called from native code): java/lang/RuntimeException

我找到了解决方法 首先,您需要创建 java URI 对象,然后将该对象传递给 NSURL 参数

例如

URL url = new URL(...path);

NSURL nsurl = new NSURL(url);