mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-04-29 22:10:12 +08:00
fix iOS10 remove local notification fail bug
This commit is contained in:
parent
8811dfc002
commit
07c9b2b945
@ -155,7 +155,12 @@ NSDictionary *_launchOptions;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
|
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:JPushDocumentEvent_ReceiveLocalNotification object:notification.userInfo];
|
NSDictionary* localNotificationEvent = @{@"content":notification.alertBody,
|
||||||
|
@"badge": @(notification.applicationIconBadgeNumber),
|
||||||
|
@"extras":notification.userInfo,
|
||||||
|
};
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:JPushDocumentEvent_ReceiveLocalNotification object:localNotificationEvent];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||||
|
@ -79,6 +79,10 @@
|
|||||||
selector:@selector(networkDidReceiveMessage:)
|
selector:@selector(networkDidReceiveMessage:)
|
||||||
name:kJPFNetworkDidReceiveMessageNotification
|
name:kJPFNetworkDidReceiveMessageNotification
|
||||||
object:nil];
|
object:nil];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(receiveLocalNotification:)
|
||||||
|
name:JPushDocumentEvent_ReceiveLocalNotification
|
||||||
|
object:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
+(void)fireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString{
|
+(void)fireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString{
|
||||||
@ -347,14 +351,50 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
-(void)setLocalNotification:(CDVInvokedUrlCommand*)command{
|
-(void)setLocalNotification:(CDVInvokedUrlCommand*)command{
|
||||||
NSLog(@"ios 10 after please use UNNotificationRequest to set local notification, see apple doc to learn more");
|
NSNumber *delay = [command argumentAtIndex:0];
|
||||||
|
NSString *alert = [command argumentAtIndex:1];
|
||||||
|
NSNumber *badge = [command argumentAtIndex:2];
|
||||||
|
NSString *idKey = [command argumentAtIndex:3];
|
||||||
|
NSDictionary *userInfo = [command argumentAtIndex:4];
|
||||||
|
|
||||||
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:[[command argumentAtIndex:0] intValue]];
|
JPushNotificationContent *content = [[JPushNotificationContent alloc] init];
|
||||||
NSString *alert = [command argumentAtIndex:1];
|
|
||||||
NSNumber *badge = [command argumentAtIndex:2];
|
if (alert) {
|
||||||
NSString *idKey = [command argumentAtIndex:3];
|
content.body = alert;
|
||||||
NSDictionary *dict = [command argumentAtIndex:4];
|
}
|
||||||
[JPUSHService setLocalNotification:date alertBody:alert badge:badge.intValue alertAction:nil identifierKey:idKey userInfo:dict soundName:nil];
|
|
||||||
|
if (badge) {
|
||||||
|
content.badge = badge;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userInfo) {
|
||||||
|
content.userInfo = userInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
JPushNotificationTrigger *trigger = [[JPushNotificationTrigger alloc] init];
|
||||||
|
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0) {
|
||||||
|
if (delay) {
|
||||||
|
trigger.timeInterval = [delay doubleValue];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (delay) {
|
||||||
|
trigger.fireDate = [NSDate dateWithTimeIntervalSinceNow:[[command argumentAtIndex:0] intValue]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JPushNotificationRequest *request = [[JPushNotificationRequest alloc] init];
|
||||||
|
request.content = content;
|
||||||
|
request.trigger = trigger;
|
||||||
|
|
||||||
|
if (idKey) {
|
||||||
|
request.requestIdentifier = idKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
request.completionHandler = ^(id result) {
|
||||||
|
NSLog(@"result");
|
||||||
|
};
|
||||||
|
|
||||||
|
[JPUSHService addNotification:request];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command{
|
-(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command{
|
||||||
@ -503,4 +543,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(void)receiveLocalNotification:(NSNotification *)notification {
|
||||||
|
if (notification && notification.object) {
|
||||||
|
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveLocalNotification
|
||||||
|
jsString:[notification.object toJsonString]];
|
||||||
|
}
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user