如何发布和接收 NSNotifications(目标 C) |通知(Swift 中)?
是否有一种易于理解的模式如何发送 NSNotification(目标 C)|通知(Swift 中)以及如何接收通知?代码片段?文档关于这个主题写了大约 150 页。想看一个简单的例子。
Is there an easy-to-grock pattern how to send a NSNotification (Objective C) | Notification (in Swift) and how to receive one? Code snippet? The docs write like 150 pages on the topic. Would like to see a quick example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
发送通知:
接收通知: 采取
行动:
并处理通知:
Send a notification:
Receive it:
Act on it:
And dispose of it:
相同的 Swift 版本:
每当您需要发布通知时:
在您想要接收通知的控制器上:
Swift Version for the same :
Whenever you need to post the notification :
On controller where you want to receive the notification :
注册推送通知配置文件并在您的应用程序中进行设置,这里有一个链接来执行此操作PushNotification(请注意,您将需要一些服务器或捕获设备推送通知 ID 的设备,以便能够向这些设备发送通知)
接下来假设您使用 Windows Server 或 .net 兼容的东西作为您的服务器,有一个很好的 C# api编写用于向苹果服务器发送推送通知(一旦您拥有存储在服务器中的证书和注册设备),这里有演示如何使用它,非常酷,这里有一个链接 C# 推送通知 src
差不多就是这样...我给了 ua使用.Net技术的快速解决方案,如果您正在使用其他东西,您可以浏览一下,看看您正在使用的平台是否有可用的解决方案,我相信您会找到一些东西,如果没有,您也可以自己制作:)
Register for a push notification profile and set it up in your application heres a link to do that PushNotification (Note you will need some server or something capturing device push notificaiton IDs in order to be able to send notification to those devices)
Next assuming you are using a Windows Server or something .net compatible as your server there is a nice C# api written to send push notifications to the apple server (once you have a certificate and devices registered for it which you have stored in your server ), there are demos in here of how to use it, pretty cool heres a link C# push notification src
Thats pretty much it...i gave u a quick solution using a .Net technology, if you are using somethign else you can browse around to see if there are solutions available in the platform you are using im sure youll find something, if not you can alwyas make your own :)