Skip to content

Commit 51e695a

Browse files
committed
Obsolete: Device.GetCountryCode()
增加:Device.GetLocaleISOCode() 以及 Device.GetLanguageISOCode()
1 parent 53c75c1 commit 51e695a

3 files changed

Lines changed: 40 additions & 32 deletions

File tree

Plugins/CS/Device.cs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,16 @@ namespace iOSNativePlugin
88
{
99
public static class Device
1010
{
11-
[DllImport("__Internal")]
12-
static extern bool Device_IsIPhoneNotchScreen();
13-
14-
[DllImport("__Internal")]
15-
static extern bool Device_IsIPad();
16-
17-
[DllImport("__Internal")]
18-
static extern int Device_GetDeviceOrientation();
19-
20-
[DllImport("__Internal")]
21-
static extern bool Audio_IsBluetoothHeadphonesConnected();
22-
23-
[DllImport("__Internal")]
24-
static extern bool Device_IsMacCatalyst();
25-
26-
[DllImport("__Internal")]
27-
static extern bool Device_IsSuperuser();
28-
29-
[DllImport("__Internal")]
30-
static extern void Audio_SetAudioExclusive(bool exclusive);
31-
32-
[DllImport("__Internal")]
33-
static extern void Device_PlayHaptics(int style, float intensity);
34-
35-
[DllImport("__Internal")]
36-
static extern string Device_GetCountryCode();
11+
[DllImport("__Internal")] static extern bool Device_IsIPhoneNotchScreen();
12+
[DllImport("__Internal")] static extern bool Device_IsIPad();
13+
[DllImport("__Internal")] static extern int Device_GetDeviceOrientation();
14+
[DllImport("__Internal")] static extern bool Audio_IsBluetoothHeadphonesConnected();
15+
[DllImport("__Internal")] static extern bool Device_IsMacCatalyst();
16+
[DllImport("__Internal")] static extern bool Device_IsSuperuser();
17+
[DllImport("__Internal")] static extern void Audio_SetAudioExclusive(bool exclusive);
18+
[DllImport("__Internal")] static extern void Device_PlayHaptics(int style, float intensity);
19+
[DllImport("__Internal")] static extern string Device_GetLocaleISOCode();
20+
[DllImport("__Internal")] static extern string Device_GetLanguageISOCode();
3721

3822
public static Version GetIOSVersion()
3923
{
@@ -112,6 +96,19 @@ public static void PlayHaptics(UIImpactFeedbackStyle style, float intensity)
11296
/// 获取当前设备的ISO地区码(ISO 3166-1 alpha-2)
11397
/// </summary>
11498
/// <returns>ISO 3166-1 alpha-2</returns>
115-
public static string GetCountryCode() => Device_GetCountryCode();
99+
[Obsolete("Use Device.GetLocaleISOCode() instead")]
100+
public static string GetCountryCode() => GetLocaleISOCode();
101+
102+
/// <summary>
103+
/// 获取当前设备的ISO地区码(ISO 3166-1 alpha-2)
104+
/// </summary>
105+
/// <returns>ISO 3166-1 alpha-2</returns>
106+
public static string GetLocaleISOCode() => Device_GetLocaleISOCode();
107+
108+
/// <summary>
109+
/// 获取当前设备语言的ISO码(ISO 3166-1 alpha-2)
110+
/// </summary>
111+
/// <returns>ISO 3166-1 alpha-2</returns>
112+
public static string GetLanguageISOCode() => Device_GetLanguageISOCode();
116113
}
117114
}

Plugins/Native/Headers/Device.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
+(BOOL)IsMacCatalyst;
88
+(BOOL)IsSuperuser;
99
+(void)PlayHaptics:(int)style _intensity:(float)intensity;
10-
+(NSString *)GetCountryCode;
10+
+(NSString *)GetLocaleISOCode;
11+
+(NSString *)GetLanguageISOCode;
1112

1213
@end
1314

@@ -30,10 +31,13 @@ extern "C"
3031
bool Device_IsSuperuser(){
3132
return [Device IsSuperuser];
3233
}
33-
const char* Device_GetCountryCode(){
34-
return StringCopy([[Device GetCountryCode] UTF8String]);
35-
}
3634
void Device_PlayHaptics(int style, float intensity){
3735
[Device PlayHaptics:style _intensity:intensity];
3836
}
37+
const char* Device_GetLocaleISOCode(){
38+
return StringCopy([[Device GetLocaleISOCode] UTF8String]);
39+
}
40+
const char* Device_GetLanguageISOCode(){
41+
return StringCopy([[Device GetLanguageISOCode] UTF8String]);
42+
}
3943
}

Plugins/Native/Implementations/Device.mm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,17 @@ +(void)PlayHaptics:(int)style _intensity:(float)intensity//参数int style,flo
7272

7373
}
7474

75-
+(NSString *)GetCountryCode{
75+
+(NSString *)GetLocaleISOCode{
7676
NSLocale *currentLocale = [NSLocale currentLocale];
7777
NSString *countryCode = [currentLocale countryCode];
7878
return countryCode;
7979
}
8080

81+
+(NSString *)GetLanguageISOCode
82+
{
83+
NSString *lang = [NSLocale preferredLanguages].firstObject;
84+
NSLocale *locale = [NSLocale localeWithLocaleIdentifier:lang];
85+
NSString *languageCode = [locale languageCode];
86+
return languageCode;
87+
}
8188
@end

0 commit comments

Comments
 (0)