Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
媒体附件在ios 10通知中裁剪图像_Ios_Swift_Apple Push Notifications_Ios10 - Fatal编程技术网

媒体附件在ios 10通知中裁剪图像

媒体附件在ios 10通知中裁剪图像,ios,swift,apple-push-notifications,ios10,Ios,Swift,Apple Push Notifications,Ios10,iOS10通知允许我们将图像作为媒体附件添加到其中。 不幸的是,我还没有找到控制通知中附件外观的好方法 例如,我将此图像添加为附件: 具体表现为: 我正在传递方形图像,希望避免图像裁剪(如您所见,猫的一只耳朵被割破) 我通过以下代码段发送通知(作为本地通知): let content = UNMutableNotificationContent() content.title = "Test notification" content.body = "Test not

iOS10通知允许我们将图像作为媒体附件添加到其中。 不幸的是,我还没有找到控制通知中附件外观的好方法

例如,我将此图像添加为附件:

具体表现为:

我正在传递方形图像,希望避免图像裁剪(如您所见,猫的一只耳朵被割破)

我通过以下代码段发送通知(作为本地通知):

    let content = UNMutableNotificationContent()
    content.title = "Test notification"
    content.body = "Test notification"
    content.categoryIdentifier = "myNotificationCategory"

    let attachement = try! UNNotificationAttachment(identifier: "image",
                                                                url: Bundle.main.url(forResource: "cat", withExtension: "png")!,
                                                                options: nil)

    content.attachments = [ attachement ]
    let request = UNNotificationRequest(identifier:requestIdentifier, content: content, trigger: nil)
    UNUserNotificationCenter.current().delegate = self
    UNUserNotificationCenter.current().add(request){(error) in
        if (error != nil){
        }
    }
所以问题是

  • 我可以避免图像裁剪吗?(如果没有-如何删除图像?)
  • 附加问题:是否有一种方法可以在一个通知中显示两个媒体附件(当它折叠时)
谢谢

您应该能够使用。然而,似乎在某个地方有一个bug:

  • ?

我回到这个非常古老的思路……我找到的解决方案(不太好!)是创建另一个正方形格式的图像(在参考资料中)。因为rect实际上是一个剪辑原始内容的正方形。

可能使用
unnotificationattachmentoptions thumbnailclippingregkey
将选项参数放入
UNNotificationAttachment
创建方法?有关详细信息,请参阅文档。@Larme谢谢您的评论!Doc看起来很有希望,但在现实生活中,它从未成功运行过(Xcode-beta5,iOS 10 beta 5)。你试过了吗?因为那只猫,我投了赞成票。(当然是个好问题)。