IOS 限制特定国家或 WLAN 对应用程序的访问
IOS restrict access to App for certain Country or WLAN
我想开发一款仅在德国可用的应用程序。
如果用户下载该应用程序并离开德国,则最好不要再使用它。这可能吗?
因为我只想知道用户当前所在的国家/地区,所以我不想询问整个位置。
此外,我想将某些内容限制在特定的 WLAN 网络中。我该怎么做?
您可以使用:
NSString *countryCode = [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode];
获取用户的国家代码。德国的国家代码是 DE。
然后您可以检查用户的国家/地区代码,如果不是 DE,则通过显示应用已锁定或类似内容的屏幕来锁定应用。
对于问题的 WLAN 部分,您可以获得用户连接到的网络的名称:
- How to get available all wifi network name Listing in iOS using swift
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
}
}
您可以检查 class 是否不等于预设 class 以阻止某些功能。
遗憾的是,地标级别没有内置 geofance。
您可以使用 region monitoring,但这需要将德国的边界重新构建为(最多 20 个)CLCircularRegion
个对象。之后,如果区域发生变化,您只需让核心位置框架通知您即可。
缺点是您只能使用 20 个圆形区域来覆盖德国的区域,因此您会损失一点精度。
第二种解决方案是使用基于计时器的检查:
- 获取当前用户位置
- 使用
CLGeocoder.reverseGeocodeLocation
,这将提供 CLPlacemark.country
- 检查我们是否还在德国
我想开发一款仅在德国可用的应用程序。
如果用户下载该应用程序并离开德国,则最好不要再使用它。这可能吗?
因为我只想知道用户当前所在的国家/地区,所以我不想询问整个位置。
此外,我想将某些内容限制在特定的 WLAN 网络中。我该怎么做?
您可以使用:
NSString *countryCode = [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode];
获取用户的国家代码。德国的国家代码是 DE。
然后您可以检查用户的国家/地区代码,如果不是 DE,则通过显示应用已锁定或类似内容的屏幕来锁定应用。
对于问题的 WLAN 部分,您可以获得用户连接到的网络的名称:
- How to get available all wifi network name Listing in iOS using swift
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 } }
您可以检查 class 是否不等于预设 class 以阻止某些功能。
遗憾的是,地标级别没有内置 geofance。
您可以使用 region monitoring,但这需要将德国的边界重新构建为(最多 20 个)CLCircularRegion
个对象。之后,如果区域发生变化,您只需让核心位置框架通知您即可。
缺点是您只能使用 20 个圆形区域来覆盖德国的区域,因此您会损失一点精度。
第二种解决方案是使用基于计时器的检查:
- 获取当前用户位置
- 使用
CLGeocoder.reverseGeocodeLocation
,这将提供CLPlacemark.country
- 检查我们是否还在德国