1

I'd like to develop an app which is only available in a germany. Preferably if a user downloads the app and leaves the germany, it should not work anymore. Is this possible?
Since i only want to know the country the user is currently i don't want to ask for the whole location.

Furthermore I'd like to restrict some content to only a specific WLAN Network. How can I do that?

Neli
  • 532
  • 1
  • 3
  • 15
  • Would limiting the app to a certain countries app store be enough? –  Jul 08 '20 at 10:07
  • I guess not because the app will still be running if a user leaves the country where he downloaded it. right? – Neli Jul 08 '20 at 10:09
  • Yeah, it will. I'll check what else I can find –  Jul 08 '20 at 10:10

2 Answers2

0

You can use:

NSString *countryCode = [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode];

To get the user's country code. The country code for Germany is DE.

You can then check the user's country code and if it isn't DE then lock the app by bringing up a screen saying the app is locked or something like that.

For the WLAN part of your question, you can get the name of the network the user is connected to:

This class will show only the wifi network name you are connected to -

    import UIKit
    import SystemConfiguration.CaptiveNetwork

    class ViewController: UIViewController {
    
        @IBOutlet weak var label: UILabel!
    
        override func viewDidLoad(){
            super.viewDidLoad()
            let ssid = self.getAllWiFiNameList()
            print("SSID: \(ssid)")
        }
        func getAllWiFiNameList() -> String? {
            var ssid: String?
            if let interfaces = CNCopySupportedInterfaces() as NSArray? {
            for interface in interfaces {
            if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? {
                        ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String
                        break
                    }
                }
            }
            return ssid
        }
    }

You can check if that class is not equal to a pre-set class to block some functionality.

  • Thanks for the answer, but the NSLocale does not return the country where the iphone is currently located, it only returns the country of the language settings – Neli Jul 08 '20 at 10:52
  • @Neli Ah yes, how about `let locale = Locale.current`? Then use `locale`? –  Jul 08 '20 at 10:53
  • This is also just the settings language code, not the current location – Neli Jul 08 '20 at 11:50
0

Unfortunately, there is no build-in geofance on placemark level.

You could use region monitoring, but this would require to re-construct the borders of Germany as (up to 20) CLCircularRegion objects. After that, you just let the core location framework inform you if a region changes.

The drawback would be that you can only use 20 circular regions to cover the area of Germany, so you'll lose a little of precision.

A second solution would be to use a timer based check:

  • get the current user location
  • use CLGeocoder.reverseGeocodeLocation, which will provide the CLPlacemark.country
  • check if we are still in Germany
Andreas Oetjen
  • 9,889
  • 1
  • 24
  • 34