To meet the laws and regulations of different countries or regions, the Agora RTC SDK supports geofencing. After enabling geofencing, the SDK only connects to Agora servers within the specified region, regardless of where your app users are located.
For example, if you specify North America as the region for connection, when two users attempt to connect to Agora servers from different locations, the result is as follows:
Specified region for connection | App user location | Actual region for connection | User experience after connection 1 |
---|---|---|---|
North America | North America | North America | Normal |
China | Can be less than optimal 2 |
As of v3.0.0.2, the Agora RTC Native SDK supports network geofencing.
When creating an AgoraRtcEngineKit
instance by calling sharedEngineWithConfig
, set the areaCode
parameter in AgoraRtcEngineConfig
to specify the region for connection.
AgoraAreaCodeGLOB
: (Default) GlobalAgoraAreaCodeCN
: Mainland ChinaAgoraAreaCodeNA
: North AmericaAgoraAreaCodeEU
: EuropeAgoraAreaCodeAS
: Asia, excluding Mainland ChinaAgoraAreaCodeJP
: JapanAgoraAreaCodeIN
: IndiaSpecify the region for connection as North America:
// Swift
let agoraRtcEngineConfig = AgoraRtcEngineConfig();
agoraRtcEngineConfig.appId = type.appId(isClassical: settings.shouldUseClassicalAppIds)
agoraRtcEngineConfig.areaCode = AgoraAreaCode.NA.rawValue
agoraKit = AgoraRtcEngineKit.sharedEngine(with: agoraRtcEngineConfig, delegate: self)
Exclude Mainland China from the regions for connection:
// Swift
let agoraRtcEngineConfig = AgoraRtcEngineConfig();
agoraRtcEngineConfig.appId = type.appId(isClassical: settings.shouldUseClassicalAppIds)
agoraRtcEngineConfig.areaCode = AgoraAreaCode.GLOB.rawValue ^ AgoraAreaCode.CN.rawValue
agoraKit = AgoraRtcEngineKit.sharedEngine(with: agoraRtcEngineConfig, delegate: self)
Specify the regions for connection as North America, Europe, Asia, and India:
// Swift
let agoraRtcEngineConfig = AgoraRtcEngineConfig();
agoraRtcEngineConfig.appId = type.appId(isClassical: settings.shouldUseClassicalAppIds)
agoraRtcEngineConfig.areaCode = AgoraAreaCode.NA.rawValue | AgoraAreaCode.EU.rawValue | AgoraAreaCode.AS.rawValue | AgoraAreaCode.IN.rawValue
agoraKit = AgoraRtcEngineKit.sharedEngine(with: agoraRtcEngineConfig, delegate: self)
If a firewall is deployed in your network environment, ensure that you whitelist all domains and ports listed in Use Cloud Proxy.