11

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?

alandalusi
  • 1,145
  • 4
  • 18
  • 39

3 Answers3

4

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

MohyG
  • 1,335
  • 13
  • 25
  • This need me to be connected to that Access Point. In Boingo, I get a notification even if I am not connected. – alandalusi Feb 20 '17 at 06:49
  • so they are using local notifications, not APNs take a look at [this](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/SchedulingandHandlingLocalNotifications.html#//apple_ref/doc/uid/TP40008194-CH5-SW1) for more info on how it works :) – MohyG Feb 20 '17 at 07:17
  • But how do you know that you are in the vacinity of the registered access point? – alandalusi Feb 20 '17 at 10:52
2

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.

Community
  • 1
  • 1
Vincent Joy
  • 2,598
  • 15
  • 25
  • The solution you provided uses GPS/Bluetooth not WiFi. What I am asking about is a pure WiFi based solution. – alandalusi Feb 14 '17 at 11:21
  • This is not an issue regarding CLLocationManager. It needs to be connected with specified WiFi hotspot. – Fenix Feb 19 '17 at 21:38
  • But reachability cannot be used if the app is in background or terminated. Also only if the app get connected to the wifi network, Reachability will know. 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. – Vincent Joy Feb 20 '17 at 07:12
1

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.

Community
  • 1
  • 1
Fenix
  • 1,552
  • 2
  • 23
  • 44
  • This will only get you the name of the connected access point. Boingo app notifies you that there is an available access point even without connecting. – alandalusi Feb 20 '17 at 06:51