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

问题描述

我正在尝试将图像添加到LibGdx项目的iOS模块中的通知中,为此我需要在UNNotificationAttachment中添加图像的URL并将此附件添加通知中心,但是在初始化UNNotificationAttachment时它仅返回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$1.invoke(NotificationDelegate.java:65)
    at ua.gram.munhauzen.NotificationDelegate$1.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 =新的NSURL(url);