Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push Notifications over WiFi

Tags:

ios

wifi

I noticed by in Boingo's Wi-Finder iOS app, that the app pushes a notification to the user once he reaches an access point regestered at Boingo's database. The notification tells the user that he can access the wifi network.

How is that done iOS?

like image 734
alandalusi Avatar asked Feb 10 '17 17:02

alandalusi


3 Answers

I think it can be done by observing the device's connectivity with Reachability class in AppDelegate 's didFinishLaunchingWithOptions and when networkStatus is equals to ReachableViaWiFi then call application.registerForRemoteNotifications()

Update : there are 2 types of notifications : Remote and Local you can configure your app to send local notification but you need to set it contents before, here you can find Apple's guide on how to handle local notification

like image 73
MohyG Avatar answered Oct 03 '22 21:10

MohyG


You can make use of CLLocationManager and UserNotifications to achieve this.

You can use the region-monitoring services like CLCircularRegion class (to get geographical regions) or CLBeaconRegion class (to get beacon regions) to get notified when the user crosses a region-based boundary. If the boundary crossing occurs even if your app isn't running, the system automatically wakes it up (or relaunches it) in the background so that it can process the event.

In this case, the options dictionary passed to the application(_:didFinishLaunchingWithOptions:) method of your app delegate contains UIApplicationLaunchOptionsKey.location. Then trigger a local notification in order to notify the user the available services in that location.

Examples:-

  1. Using location monitoring:- https://www.raywenderlich.com/136165/core-location-geofencing-tutorial
  2. Using iBeacons - https://www.raywenderlich.com/101891/ibeacons-tutorial-ios-swift

NB. As suggested in other answers Reachability class also we can use. But Reachability cannot be used if the app is in background or terminated. To trigger reachability when app is in background we can follow this: https://stackoverflow.com/a/35615381/4637057. But unfortunately, the disadvantage here is, the more often the Background Fetch is set to work to an app, the more resources will be used. iOS protects itself and the device by applying limitations to the apps that try to use the API very often, so be cautious when setting custom time intervals. Also Background Fetch will cause a battery drain very quickly.

Also only if the app get connected to that wifi network, Reachability can trigger notification. But Boingo will notify the user even if the app is in background and phone is not yet connected to the wifi. So I strongly suspect they are using location services to detect whether user entered an area where wifi is available.

like image 25
Vincent Joy Avatar answered Oct 03 '22 20:10

Vincent Joy


You can get the SSID of the Wifi hotspot and if it's registered one, you can follow Mohy's answers. Please check the following link.

How to get Wifi SSID in iOS9 after CaptiveNetwork is deprecated and calls for Wifi name are already blocked

This will help you to get the SSID of Wifi hotspot.

like image 45
Phoenix Avatar answered Oct 03 '22 21:10

Phoenix