Skip to content

Commit 6144d15

Browse files
committed
新增iOSApplication 设置AlternateIcon相关API
1 parent e8c39f4 commit 6144d15

3 files changed

Lines changed: 61 additions & 42 deletions

File tree

Plugins/CS/iOSApplication.cs

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,32 @@ namespace iOSNativePlugin
99
{
1010
public static class iOSApplication
1111
{
12-
[DllImport("__Internal")]
13-
static extern string iOSApplication_GetBundleIdentifier();
14-
15-
[DllImport("__Internal")]
16-
static extern string iOSApplication_GetVersion();
17-
18-
[DllImport("__Internal")]
19-
static extern string iOSApplication_GetBundleVersion();
20-
21-
[DllImport("__Internal")]
22-
static extern void iOSApplication_OpenAppSettings();
23-
24-
[DllImport("__Internal")]
25-
static extern void iOSApplication_SetUserSettingsBool(string identifier, bool value);
26-
27-
[DllImport("__Internal")]
28-
static extern bool iOSApplication_GetUserSettingsBool(string identifier);
29-
30-
[DllImport("__Internal")]
31-
static extern void iOSApplication_SetUserSettingsString(string identifier, string value);
32-
33-
[DllImport("__Internal")]
34-
static extern string iOSApplication_GetUserSettingsString(string identifier);
35-
36-
[DllImport("__Internal")]
37-
static extern void iOSApplication_SetUserSettingsFloat(string identifier, float value);
38-
39-
[DllImport("__Internal")]
40-
static extern float iOSApplication_GetUserSettingsFloat(string identifier);
41-
42-
[DllImport("__Internal")]
43-
static extern void iOSApplication_SetUserSettingsInt(string identifier, long value);
44-
45-
[DllImport("__Internal")]
46-
static extern long iOSApplication_GetUserSettingsInt(string identifier);
12+
[DllImport("__Internal")] static extern string iOSApplication_GetBundleIdentifier();
13+
[DllImport("__Internal")] static extern string iOSApplication_GetVersion();
14+
[DllImport("__Internal")] static extern string iOSApplication_GetBundleVersion();
15+
[DllImport("__Internal")] static extern void iOSApplication_OpenAppSettings();
16+
[DllImport("__Internal")] static extern void iOSApplication_SetAlternateIconName(string iconName);
17+
[DllImport("__Internal")] static extern string iOSApplication_GetAlternateIconName();
18+
[DllImport("__Internal")] static extern void iOSApplication_SetUserSettingsBool(string identifier, bool value);
19+
[DllImport("__Internal")] static extern bool iOSApplication_GetUserSettingsBool(string identifier);
20+
[DllImport("__Internal")] static extern void iOSApplication_SetUserSettingsString(string identifier, string value);
21+
[DllImport("__Internal")] static extern string iOSApplication_GetUserSettingsString(string identifier);
22+
[DllImport("__Internal")] static extern void iOSApplication_SetUserSettingsFloat(string identifier, float value);
23+
[DllImport("__Internal")] static extern float iOSApplication_GetUserSettingsFloat(string identifier);
24+
[DllImport("__Internal")] static extern void iOSApplication_SetUserSettingsInt(string identifier, long value);
25+
[DllImport("__Internal")] static extern long iOSApplication_GetUserSettingsInt(string identifier);
26+
[DllImport("__Internal")] static extern void iOSApplication_RegisterUserSettingsChangeCallback(UserSettingsChangeCallback callback);
27+
[DllImport("__Internal")] static extern void iOSApplication_UnregisterUserSettingsChangeCallback();
4728

48-
[DllImport("__Internal")]
49-
static extern void iOSApplication_RegisterUserSettingsChangeCallback(UserSettingsChangeCallback callback);
50-
51-
[DllImport("__Internal")]
52-
static extern void iOSApplication_UnregisterUserSettingsChangeCallback();
53-
54-
29+
public static string GetAlternateIconName()
30+
{
31+
return iOSApplication_GetAlternateIconName();
32+
}
33+
34+
public static void SetAlternateIconName(string iconName)
35+
{
36+
iOSApplication_SetAlternateIconName(iconName);
37+
}
5538
/// <summary>
5639
/// 获取当前应用的Bundle Identifier
5740
/// </summary>

Plugins/Native/Headers/iOSApplication.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
+(NSString *)GetBundleIdentifier;
77
+(NSString *)GetVersion;
88
+(NSString *)GetBundleVersion;
9+
+(NSString *)GetAlternateIconName;
10+
+(void)SetAlternateIconName:(NSString *)iconName;
911

1012
+(void)SetUserSettingsBool:(NSString *) identifier value:(bool) value;
1113
+(BOOL)GetUserSettingsBool:(NSString *) identifier;
@@ -23,6 +25,26 @@
2325

2426
extern "C"
2527
{
28+
29+
const char* iOSApplication_GetAlternateIconName()
30+
{
31+
NSString * str = [iOSApplication GetAlternateIconName];
32+
if(str == nil){
33+
return nullptr;
34+
}
35+
36+
return StringCopy([str UTF8String]);
37+
}
38+
39+
void iOSApplication_SetAlternateIconName(const char* iconName){
40+
if(iconName == nullptr){
41+
[iOSApplication SetAlternateIconName:nil];
42+
return;
43+
}
44+
[iOSApplication SetAlternateIconName:[NSString stringWithUTF8String:iconName]];
45+
}
46+
47+
2648
const char* iOSApplication_GetBundleIdentifier()
2749
{
2850
return StringCopy([[iOSApplication GetBundleIdentifier] UTF8String]);

Plugins/Native/Implementations/iOSApplication.mm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ +(void)OpenAppSettings
2828

2929
}];
3030
}
31+
3132
+(NSString *)GetBundleIdentifier
3233
{
3334
return [[NSBundle mainBundle] bundleIdentifier];
@@ -41,6 +42,19 @@ +(NSString *)GetBundleVersion
4142
return [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey];
4243
}
4344

45+
+(void)SetAlternateIconName:(NSString *)iconName
46+
{
47+
[[UIApplication sharedApplication] setAlternateIconName:iconName completionHandler:^(NSError * _Nullable error) {
48+
if(error != nil){
49+
LOG([@"Failed to set alternate icon" stringByAppendingString:error.localizedDescription]);
50+
}
51+
52+
}];
53+
}
54+
55+
+ (NSString *)GetAlternateIconName {
56+
return [[UIApplication sharedApplication] alternateIconName];
57+
}
4458
// Bool
4559
+(void)SetUserSettingsBool:(NSString *) identifier value:(bool) value
4660
{

0 commit comments

Comments
 (0)