Skip to content

Commit

Permalink
iOS version check
Browse files Browse the repository at this point in the history
  • Loading branch information
joeykamsteeg committed Jun 15, 2017
1 parent ba45349 commit 122be1d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 29 deletions.
74 changes: 46 additions & 28 deletions ReactNativeAlternateIcons.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,68 @@

@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){
NSLog(@"Setting the following icon: %@", name);
[[UIApplication sharedApplication] setAlternateIconName:name completionHandler:^(NSError * _Nullable error) {
if( error != nil ){
NSLog(@"Error: %@", error.description );
}
}];
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){
[[UIApplication sharedApplication] setAlternateIconName:nil completionHandler:^(NSError * _Nullable error) {
if( error != nil ){
NSLog(@"Error: %@", error.description );
}
}];
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 ){
//resolve( [[UIApplication sharedApplication] alternateIconName] );]
NSString *name = [[UIApplication sharedApplication] alternateIconName];
if( name == nil ){
name = @"default";
}
NSString *name = @"default";
NSDictionary *results;

NSDictionary *results = @{
@"iconName":name
};
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;
NSDictionary *results = @{
@"supported":@NO
};

if( [[UIApplication sharedApplication] supportsAlternateIcons ] ){
results = @{
@"supported":YES
};
}else{
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]);
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-alternate-icons",
"version": "0.2.0",
"version": "0.3.0",
"description": "React Native Alternate Icons for iOS 10.3+",
"main": "ReactNativeAlternateIcons.ios.js",
"scripts": {
Expand Down

0 comments on commit 122be1d

Please sign in to comment.