Commit 15d3d3e1 by Sebastián Katzer

Fix UI main thread warnings with iOS11

parent 2e0bcaf0
...@@ -27,9 +27,9 @@ ...@@ -27,9 +27,9 @@
@interface APPLocalNotification () @interface APPLocalNotification ()
@property (strong, nonatomic) UIApplication* app;
@property (strong, nonatomic) UNUserNotificationCenter* center; @property (strong, nonatomic) UNUserNotificationCenter* center;
@property (readwrite, assign) BOOL deviceready; @property (readwrite, assign) BOOL deviceready;
@property (readwrite, assign) BOOL isActive;
@property (readonly, nonatomic, retain) NSArray* launchDetails; @property (readonly, nonatomic, retain) NSArray* launchDetails;
@property (readonly, nonatomic, retain) NSMutableArray* eventQueue; @property (readonly, nonatomic, retain) NSMutableArray* eventQueue;
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
@implementation APPLocalNotification @implementation APPLocalNotification
@synthesize deviceready, eventQueue; @synthesize deviceready, isActive, eventQueue;
#pragma mark - #pragma mark -
#pragma mark Interface #pragma mark Interface
...@@ -169,7 +169,7 @@ ...@@ -169,7 +169,7 @@
{ {
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
[_center clearAllNotifications]; [_center clearAllNotifications];
[_app setApplicationIconBadgeNumber:0]; [self clearApplicationIconBadgeNumber];
[self fireEvent:@"clearall"]; [self fireEvent:@"clearall"];
[self execCallback:command]; [self execCallback:command];
}]; }];
...@@ -210,7 +210,7 @@ ...@@ -210,7 +210,7 @@
{ {
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
[_center cancelAllNotifications]; [_center cancelAllNotifications];
[_app setApplicationIconBadgeNumber:0]; [self clearApplicationIconBadgeNumber];
[self fireEvent:@"cancelall"]; [self fireEvent:@"cancelall"];
[self execCallback:command]; [self execCallback:command];
}]; }];
...@@ -560,17 +560,44 @@ ...@@ -560,17 +560,44 @@
- (void) pluginInitialize - (void) pluginInitialize
{ {
eventQueue = [[NSMutableArray alloc] init]; eventQueue = [[NSMutableArray alloc] init];
_app = [UIApplication sharedApplication];
_center = [UNUserNotificationCenter currentNotificationCenter]; _center = [UNUserNotificationCenter currentNotificationCenter];
_center.delegate = self; _center.delegate = self;
[_center registerGeneralNotificationCategory]; [_center registerGeneralNotificationCategory];
[self monitorAppStateChanges];
}
/**
* Monitor changes of the app state and update the _isActive flag.
*/
- (void) monitorAppStateChanges
{
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserverForName:UIApplicationDidBecomeActiveNotification
object:NULL queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *e) { isActive = YES; }];
[center addObserverForName:UIApplicationDidEnterBackgroundNotification
object:NULL queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *e) { isActive = NO; }];
} }
#pragma mark - #pragma mark -
#pragma mark Helper #pragma mark Helper
/** /**
* Removes the badge number from the app icon.
*/
- (void) clearApplicationIconBadgeNumber
{
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
});
}
/**
* Simply invokes the callback without any parameter. * Simply invokes the callback without any parameter.
*/ */
- (void) execCallback:(CDVInvokedUrlCommand*)command - (void) execCallback:(CDVInvokedUrlCommand*)command
...@@ -625,7 +652,6 @@ ...@@ -625,7 +652,6 @@
notification:(UNNotificationRequest*)request notification:(UNNotificationRequest*)request
data:(NSMutableDictionary*)data data:(NSMutableDictionary*)data
{ {
BOOL isActive = [_app applicationState] == UIApplicationStateActive;
NSString *js, *params, *notiAsJSON, *dataAsJSON; NSString *js, *params, *notiAsJSON, *dataAsJSON;
NSData* dataAsData; NSData* dataAsData;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment