Created
April 13, 2021 06:46
-
-
Save hungtrn75/5603b680db35aff69d2c81cc3e4964af to your computer and use it in GitHub Desktop.
Progress Dialog iOS Native Module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // CBNative.h | |
| // ecoffice | |
| // | |
| // Created by Suni on 4/13/21. | |
| // | |
| #import <React/RCTBridgeModule.h> | |
| @interface CBNative : NSObject <RCTBridgeModule> | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // CBNative.m | |
| // ecoffice | |
| // | |
| // Created by Suni on 4/13/21. | |
| // | |
| #import <UIKit/UIKit.h> | |
| #import "CBNative.h" | |
| #import "SVProgressHUD.h" | |
| #import "DeviceUtil.h" | |
| @implementation CBNative | |
| RCT_EXPORT_MODULE(); | |
| - (NSDictionary *)constantsToExport | |
| { | |
| return @{ | |
| @"appVersion" : [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], | |
| @"buildVersion": [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey], | |
| @"bundleIdentifier" : [[NSBundle mainBundle] bundleIdentifier], | |
| @"imei" : [DeviceUtil getImei] | |
| }; | |
| } | |
| RCT_EXPORT_METHOD(showLoading) | |
| { | |
| [SVProgressHUD setBackgroundColor:UIColor.clearColor]; | |
| [SVProgressHUD setRingThickness:3]; | |
| [SVProgressHUD setForegroundColor:UIColor.whiteColor]; | |
| [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack]; | |
| [SVProgressHUD showWithStatus:@"Đang xử lý"]; | |
| } | |
| RCT_EXPORT_METHOD(hideLoading) | |
| { | |
| [SVProgressHUD dismiss]; | |
| } | |
| RCT_EXPORT_METHOD(exitApp) | |
| { | |
| exit(0); | |
| } | |
| - (dispatch_queue_t)methodQueue | |
| { | |
| return dispatch_get_main_queue(); | |
| } | |
| + (BOOL)requiresMainQueueSetup | |
| { | |
| return YES; | |
| } | |
| @end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // DeviceUtil.h | |
| // ecoffice | |
| // | |
| // Created by Suni on 4/13/21. | |
| // | |
| #import <Foundation/Foundation.h> | |
| @interface DeviceUtil : NSObject | |
| +(NSString*)getImei; | |
| @end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // DeviceUtil.m | |
| // ecoffice | |
| // | |
| // Created by Suni on 4/13/21. | |
| // | |
| #import "DeviceUtil.h" | |
| #import "NSUserDefaults+Helper.h" | |
| #import <UIKit/UIKit.h> | |
| @implementation DeviceUtil | |
| + (NSString*)getImei { | |
| NSString* imei = (NSString*)[NSUserDefaults getObjectWithKey:@"KEY_IMEI"]; | |
| if (imei == nil || [imei isEqualToString:@""]) { | |
| imei = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; | |
| } | |
| [NSUserDefaults setObjectWithKey:imei key:@"KEY_IMEI"]; | |
| return imei; | |
| } | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // NSUserDefaults+Helper.h | |
| // ecoffice | |
| // | |
| // Created by Suni on 4/13/21. | |
| // | |
| #import <Foundation/Foundation.h> | |
| @interface NSUserDefaults (Helper) | |
| + (void)setObjectWithKey:(NSObject *)object key:(NSString *)key; | |
| + (NSObject *)getObjectWithKey:(NSString *)key; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // NSUserDefaults+Helper.m | |
| // ecoffice | |
| // | |
| // Created by Suni on 4/13/21. | |
| // | |
| #import "NSUserDefaults+Helper.h" | |
| @implementation NSUserDefaults (Helper) | |
| + (void)setObjectWithKey:(NSObject *)object key:(NSString *)key { | |
| NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:object]; | |
| NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
| [defaults setObject:encodedObject forKey:key]; | |
| NSLog(@"%@ saved in NSUserDefaults", key); | |
| [defaults synchronize]; | |
| } | |
| + (NSObject *)getObjectWithKey:(NSString *)key { | |
| NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
| NSData *encodedObject = [defaults objectForKey:key]; | |
| NSObject *object = [NSKeyedUnarchiver unarchiveObjectWithData:encodedObject]; | |
| return object; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment