如何分配->发送->收到->演员->将UnsafeRawPointer从扩展名分配到应用程序? [英] How to allocate -> send -> receive -> cast -> deallocate UnsafeRawPointer from extension to app?

查看:107
本文介绍了如何分配->发送->收到->演员->将UnsafeRawPointer从扩展名分配到应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是UnsafeRawPointer的新手. 如我所知,我需要在扩展程序中分配不安全的内存,并将指针发送到我的应用程序,该应用程序必须进行强制转换和释放. 以下是我想做的草图. 我想从Safari扩展程序发送string message并通过CFNotificationCenterGetDarwinNotifyCenter在应用程序中接收它,该怎么做?

I am new in UnsafeRawPointer. As I got I need to allocate unsafe memory in my extension and send pointer to my app where has to cast and release it. Below is a sketch of what I want to do. I'd like to send a string message from Safari extension and receive it in app by CFNotificationCenterGetDarwinNotifyCenter, how to do it?

let center = CFNotificationCenterGetDarwinNotifyCenter()

CFNotificationCenterAddObserver(center, nil, { (_, observer, name, message, _) -> Void in
    //message as String???             
}, Self.action, nil, .deliverImmediately)

var message = "some text"
CFNotificationCenterPostNotification(center, .init(action), message, nil, true)

主要问题?

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆