ℹ️ A library for blocking specific application features based on the user's region
- Language check
- Region check
- Location check
- IP check
- Async/await
- iOS 12+
The example application is the best way to see RegionBlocker in action. Simply open the RegionBlockerExample.xcodeproj and run the Example scheme.
To integrate using Apple's Swift Package Manager, add the following as a dependency to your Package.swift:
dependencies: [
.package(url: "https://github.com/moslienko/RegionBlocker.git", from: "1.0.0")
]Alternatively navigate to your Xcode project, select Swift Packages and click the + icon to search for RegionBlocker.
If you prefer not to use any of the aforementioned dependency managers, you can integrate RegionBlocker into your project manually. Simply drag the Sources Folder into your Xcode project.
RegionService.shared.allowedRegions = [CountryCode.Russia.rawValue, CountryCode.Belarus.rawValue]
RegionService.shared.allowedLanguages = ["ru", "be"]
RegionService.shared.checkMethods = RegionBlockerMethod.allCasesTo check the region, you must first call the next code (for example after the application initialization, on the splash screen, before the main screen is shown):
RegionService.shared.checkRegion { isAllowed in }In the later case, you can simply refer to the variable:
RegionService.shared.isAllowedYou can also use async/await. Please note that if you choose the geolocation method, you will need to manually provide the user coordinates, for example using your own async geolocation service.
RegionService.shared.checkMethods = [.byLocation]
let isAllowed = await RegionService.shared.checkRegion(location: CLLocation(latitude: 55.7558, longitude: 37.6173))Depending on the region check methods selected, make sure that the required items are added to info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string>To provide features available in your region</string>RegionBlocker
Copyright (c) 2024 Pavel Moslienko 8676976+moslienko@users.noreply.github.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
