简体   繁体   English

不使用互联网,wifi,APNS和苹果推送通知服务器推送通知

[英]Push Notification without using internet,wifi,APNS and apple push notification server

I need to write an IOS app to let a few IOS devices to send local notifications to each other WITHOUT external Internet connection (without using APNS -- apple push notification server). 我需要编写一个IOS应用程序,让一些IOS设备在没有外部Internet连接的情况下相互发送本地通知(不使用APNS - 苹果推送通知服务器)。 The environment will be a private internal WIFI network with a dedicated server... 环境将是一个私人内部WIFI网络,带有专用服务器......

Scanario Scanario

we work in a bank office all 14 people using Iphones Person A send notification to rest of the 13 people all will recieve the notification one person in the group (for example, Person H) reply back and Person A can recieve Person H's reply not external internet all iphone what we have is a private wifi network, set up by a server . 我们在银行办公室工作所有14个人使用Iphone人员A发送通知给13个人中的其他人都将收到通知组中的一个人(例如,人H)回复和A人可以收到人H的回复而不是外部互联网所有iphone我们拥有的是一个私人wifi网络,由服务器设置。 TOTALLY NO LINK to outside world..no link to outside internet 完全没有链接到外面的世界..没有链接到外部互联网

If it is possible in ios app. 如果有可能在ios应用程序中。 using swift 3.0. 使用swift 3.0。 If It's possible can you please guide me. 如果有可能请指导我。

You can implement this kind of functionality by using a combination Background fetch ( Apple documentation ) and local notifications , if you have a server inside the network that contains the information which is needed to show the notification. 如果网络中的服务器包含显示通知所需的信息,则可以使用组合后台提取Apple文档 )和本地通知来实现此类功能。 Conceptually this would work like this: 从概念上讲,这将是这样的:

  1. Setup the app to fetch the data periodically from your server inside internal network using background fetch functionality. 设置应用程序以使用后台获取功能定期从内部网络内的服务器获取数据。
  2. When the server sends you the information that should notify the user, show the local notification. 当服务器向您发送应通知用户的信息时,显示本地通知。

There are three things to remember in this approach, though. 但是,这种方法有三点要记住。

  • Your app does not receive the notification if it is not running in the background, ie your users will need to remember to keep the app running in the background. 如果您的应用未在后台运行,则您的应用不会收到通知,即您的用户需要记住让应用在后台运行。
  • The background data fetch is not completely reliable, and Apple may not fire it on time ie. 后台数据获取并不完全可靠,Apple可能无法按时启动它,即。 when the device is in the battery save mode. 当设备处于省电模式时。 This may or may not be okay for your use case (you'd want to test it). 这可能适用于您的用例,也可能不适用(您需要对其进行测试)。
  • You need to test that your iPhones do not disconnect from the wifi when going to the sleep mode; 你需要测试你的iPhone在进入睡眠模式时不会与wifi断开连接; otherwise your background fetch logic will not work. 否则你的后台获取逻辑将无效。

EDIT: For example like this: 编辑:例如这样:

  1. In project settings, enable Capabilities -> Background Modes -> Background fetch 在项目设置中,启用功能 - >背景模式 - >后台提取
  2. set minimum interval in your AppDelegate.didFinishWithLaunchOptions method, for example: AppDelegate.didFinishWithLaunchOptions方法中设置最小间隔,例如:

UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)

  1. implement the handler method in the AppDelegate: 在AppDelegate中实现handler方法:

func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping 
(UIBackgroundFetchResult) -> Void {
    fetchData() { data in 
         if data.needsToBeNotified {
             sendLocalNotification()
         }
         completionHandler(.newData)
    }
}

RayWenderlich have a nice tutorial about the background modes: https://www.raywenderlich.com/143128/background-modes-tutorial-getting-started RayWenderlich有一个很好的关于背景模式的教程: https ://www.raywenderlich.com/143128/background-modes-tutorial-getting-started

The scenario can be addressed using MQTT Protocol within the Wi-Fi network. 可以使用Wi-Fi网络内的MQTT协议来解决该场景。 You will have to set up an MQTT Broker within the network and Make an MQTT Client in your iOs App. 您必须在网络中设置MQTT Broker并在您的iOs应用程序中创建MQTT客户端。 You can subscribe the MQTT Client to the MQTT broker on a topic same as GCM works and use MQTT Broker to send Push Notification to topics subscribed by MQTT Clients. 您可以在与GCM相同的主题上将MQTT客户端订阅到MQTT代理,并使用MQTT Broker将推送通知发送到MQTT客户端订阅的主题。

Example for Android Android的示例

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM