【问题标题】:UNNotificationAttachment null while initalizing for Rich Notification in Libgdx iOS module在 Libgdx iOS 模块中初始化丰富通知时 UNNotificationAttachment 为空
【发布时间】:2020-12-12 12:44:54
【问题描述】:

我正在尝试将图像添加到 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

【问题讨论】:

    标签: ios firebase push-notification libgdx apple-push-notifications


    【解决方案1】:

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

    例如

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

    NSURL nsurl = 新的 NSURL(url);

    【讨论】:

      猜你喜欢
      • 2020-12-14
      • 1970-01-01
      • 1970-01-01
      • 2020-07-08
      • 1970-01-01
      • 1970-01-01
      • 2022-11-13
      • 2017-04-04
      • 1970-01-01
      相关资源
      最近更新 更多