【问题标题】:Unable to insert COPY_SEND when programatically calling VC in Notification Content Extension在通知内容扩展中以编程方式调用 VC 时无法插入 COPY_SEND
【发布时间】:2019-03-18 05:34:22
【问题描述】:

创建通知内容扩展,然后删除 NSExtensionMainStoryboard 并将其替换为 info.plist 文件中的 NSExtensionPrincipalClass 并适当地调用 module.viewController 然后调试扩展我看到以下错误?

NotificationExtension[58062:21665141] [Common] _BSMachError: port 5c03; (os/kern) 无效能力 (0x14) “无法插入 COPY_SEND”

下面是 NotificationExtensionViewControllerCode

import UIKit
import UserNotifications
import UserNotificationsUI

class NotificationViewController: UIViewController, UNNotificationContentExtension {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any required interface initialization here.
    }

    func didReceive(_ notification: UNNotification) {

    }

}

是什么导致了错误,我该如何解决?

如果您执行上述相同操作,但使用 NSExtensionMainStoryboard 调用情节提要但删除标签,您会得到相同的错误!

提前致谢。

【问题讨论】:

    标签: ios swift usernotifications


    【解决方案1】:

    您需要在附件网址(didReceive)上调用startAccessingSecurityScopedResource()。 Apple 的一些天才认为通知扩展只访问 通知存储 中的文件是很危险的。当然它有据可查(不是!)

    if let attachment = notification.request.content.attachments.first {
        if attachment.url.startAccessingSecurityScopedResource() {
            if let data = NSData(contentsOfFile: attachment.url.path) as? Data {
                self.uiImage.image = UIImage(data: data) // <- that's the image view
                attachment.url.stopAccessingSecurityScopedResource()
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-27
      • 1970-01-01
      相关资源
      最近更新 更多