-
Notifications
You must be signed in to change notification settings - Fork 21
/
ReactNativeAlternateIcons.m
75 lines (63 loc) · 2.68 KB
/
ReactNativeAlternateIcons.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#import "ReactNativeAlternateIcons.h"
#import <React/RCTLog.h>
#import <React/RCTClipboard.h>
#import <UIKit/UIKit.h>
@implementation ReactNativeAlternateIcons
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(setIconName:(NSString *)name){
if( SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.3") ){
[[UIApplication sharedApplication] setAlternateIconName:name completionHandler:^(NSError * _Nullable error) {
if( error != nil ){
NSLog(@"Error: %@", error.description );
}
}];
}
}
RCT_EXPORT_METHOD(reset){
if( SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.3") ){
[[UIApplication sharedApplication] setAlternateIconName:nil completionHandler:^(NSError * _Nullable error) {
if( error != nil ){
NSLog(@"Error: %@", error.description );
}
}];
}
}
RCT_EXPORT_METHOD(getIconName:(RCTResponseSenderBlock) callback ){
NSString *name = @"default";
NSDictionary *results;
if( SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.3") ){
if( [[UIApplication sharedApplication] supportsAlternateIcons ] ){
name = [[UIApplication sharedApplication] alternateIconName];
if( name == nil ){
name = @"default";
}
}
}
results = @{
@"iconName":name
};
callback(@[results]);
}
RCT_EXPORT_METHOD(supportDevice:(RCTResponseSenderBlock) callback){
NSDictionary *results = @{
@"supported":@NO
};
if( SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.3") ){
if( [[UIApplication sharedApplication] supportsAlternateIcons ] ){
results = @{
@"supported":@YES
};
}else{
results = @{
@"supported":@NO
};
}
}
callback(@[results]);
}
@end