简体   繁体   English

iOS/Swift:向另一台设备发送通知的快速而肮脏的方式?

[英]iOS/Swift: Quick & dirty way to send a notification to another device?

I'm trying to write a super-simple iOS app, just for personal use (ie it doesn't need to conform to any App Store stuff).我正在尝试编写一个超级简单的 iOS 应用程序,仅供个人使用(即它不需要符合任何 App Store 的东西)。 I want it to do the following.我希望它执行以下操作。 Assume it's installed on two devices, both of which I own/control.假设它安装在两个我拥有/控制的设备上。

On device 1, it has a button that, when pressed, will immediately cause a notification to pop up on device 2.在设备 1 上,它有一个按钮,当按下该按钮时,将立即在设备 2 上弹出通知。

I'm fine with hardcoding specific apple IDs, device IDs, whatever;我可以硬编码特定的苹果 ID、设备 ID 等等; it's also fine if this only works when the two devices are on the same LAN/Wifi.如果这仅在两个设备位于同一 LAN/Wifi 上时有效,那也很好。 all I want is for the above to work, in the easiest way possible, and preferably without needing anything to run on a server anywhere.我想要的只是让上述工作以最简单的方式工作,最好不需要任何东西在任何地方的服务器上运行。

How simply can this be implemented?实现起来有多简单? I've set up a whole push-notification system once before, but that required some server-side stuff.我之前建立了一个完整的推送通知系统,但这需要一些服务器端的东西。 Hoping to be able to do this without any of that.希望能够做到这一点,而无需任何这些。

==== ====

Update : realized I wasn't clear in the original post that I need the notification on Device 2 to pop up whether or not the app is currently open/running on that device.更新:意识到我在原始帖子中并不清楚我需要设备 2 上的通知来弹出应用程序当前是否在该设备上打开/运行。

I think that what you are searching for is multipeer connectivity framework.我认为您正在寻找的是多点连接框架。

The Multipeer Connectivity framework supports the discovery of services provided by nearby devices and supports communicating with those services through message-based data, streaming data, and resources (such as files). Multipeer Connectivity 框架支持发现附近设备提供的服务,并支持通过基于消息的数据、流数据和资源(例如文件)与这些服务进行通信。 In iOS, the framework uses infrastructure Wi-Fi networks, peer-to-peer Wi-Fi, and Bluetooth personal area networks for the underlying transport.在 iOS 中,该框架使用基础设施 Wi-Fi 网络、对等 Wi-Fi 和蓝牙个人区域网络进行底层传输。 In macOS and tvOS, it uses infrastructure Wi-Fi, peer-to-peer Wi-Fi, and Ethernet.在 macOS 和 tvOS 中,它使用基础设施 Wi-Fi、点对点 Wi-Fi 和以太网。

source:https://developer.apple.com/documentation/multipeerconnectivity .来源:https ://developer.apple.com/documentation/multipeerconnectivity。

You can also check those tutorials:您还可以查看这些教程:

https://www.ralfebert.com/ios-app-development/multipeer-connectivity/ https://www.ralfebert.com/ios-app-development/multipeer-connectivity/

https://www.hackingwithswift.com/example-code/networking/how-to-create-a-peer-to-peer-network-using-the-multipeer-connectivity-framework https://www.hackingwithswift.com/example-code/networking/how-to-create-a-peer-to-peer-network-using-the-multipeer-connectivity-framework

Send sms to port is a way (the protocol will become SMS): https://developer.apple.com/documentation/foundation/nsportmessage发送短信到端口是一种方式(协议会变成短信): https ://developer.apple.com/documentation/foundation/nsportmessage

and Maybe Firebase Remote Config can help you: you can get your data in FCM remote config (key-value) from the app : https://www.raywenderlich.com/17323848-firebase-remote-config-tutorial-for-ios https://firebase.google.com/docs/remote-config/get-started?platform=ios , and you can modify your data whenever you want, and the app can fetch it.也许 Firebase 远程配置可以帮助您:您可以从应用程序获取 FCM 远程配置(键值)中的数据: https ://www.raywenderlich.com/17323848-firebase-remote-config-tutorial-for-ios https://firebase.google.com/docs/remote-config/get-started?platform=ios ,您可以随时修改您的数据,并且应用程序可以获取它。

I have similar requirements, and it seems like APNS (Apple Push Notification Service) is required for this because it's one of the only ways to 'activate' an application that is in the background.我有类似的要求,似乎需要 APNS(Apple Push Notification Service),因为它是“激活”后台应用程序的唯一方法之一。

As a result, then the question is how to make APNS as painless as possible?那么问题来了,如何让APNS尽可能的无痛? It seems like combining Firebase Cloud Messaging (or FCM) (to manage APNS / sending messages), and Firebase Functions (to help manage FCM server-side requirements) is one decent option.似乎将Firebase Cloud Messaging(或 FCM) (用于管理 APNS/发送消息)和 Firebase 功能(以帮助管理 FCM 服务器端要求)结合起来是一种不错的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ios使用GCM设备向设备发送推送通知 - ios send push notification with GCM Device to Device 设备旋转通知无法按预期方式运行iOS Swift - Device Rotation Notification is not working as expected iOS Swift Laravel 5将推送通知发送到android和ios设备 - Laravel 5 send push notification to android and ios device iOS是否将推送通知发送到没有应用程序的设备? - iOS Send Push Notification to a device WITHOUT an application? 将数据发送到Android设备通知到IOS设备 - Send data to Android device Notification to IOS devices 直接从设备swift将推送通知发送到设备3 - send push notification to device directly from a device swift 3 设备令牌无效时将推送通知发送到ios设备崩溃 - Send push notification to ios device crash when device token is invalid Aerogear-如何将推送通知从一台设备发送到另一台设备 - Aerogear - how to send a push notification from one device to another device Firebase、Swift:向给定设备令牌的特定用户发送推送通知 - Firebase, Swift: Send a push notification to specific user given device token 将小型视频从一台iOS设备发送到另一台设备的最快方法是什么? - What is the fastest way to send a small video from one iOS device to another?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM