Skip to content

Commit c80f769

Browse files
committed
update fix demo to link native plugin
1 parent d12d602 commit c80f769

File tree

7 files changed

+62
-56
lines changed

7 files changed

+62
-56
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 0.0.10
1+
## 0.0.11
22

33
iOS: 修复 getLaunchAppNotification 返回 null 的情况。
44
featurn: APNS 推送字段将 extras 字段移动到 notification.extras 中和 android 保持一致。

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
```yaml
99
dependencies:
10-
jpush_flutter: 0.0.10
10+
jpush_flutter: 0.0.11
1111
```
1212
1313
### 配置

example/lib/main.dart

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,22 @@ final JPush jpush = new JPush();
116116
});
117117

118118
}),
119+
new FlatButton(
120+
child: new Text('getLaunchAppNotification\n'),
121+
onPressed: () {
122+
123+
jpush.getLaunchAppNotification().then((map) {
124+
setState(() {
125+
debugLable = "getLaunchAppNotification success: $map";
126+
});
127+
})
128+
.catchError((error) {
129+
setState(() {
130+
debugLable = "getLaunchAppNotification error: $error";
131+
});
132+
});
119133

134+
}),
120135
new FlatButton(
121136
child: new Text('applyPushAuthority\n'),
122137
onPressed: () {
@@ -271,22 +286,7 @@ final JPush jpush = new JPush();
271286
jpush.clearAllNotifications();
272287

273288
}),
274-
new FlatButton(
275-
child: new Text('getLaunchAppNotification\n'),
276-
onPressed: () {
277-
278-
jpush.getLaunchAppNotification().then((map) {
279-
setState(() {
280-
debugLable = "getLaunchAppNotification success: $map";
281-
});
282-
})
283-
.catchError((error) {
284-
setState(() {
285-
debugLable = "getLaunchAppNotification error: $error";
286-
});
287-
});
288-
289-
}),
289+
290290

291291
]
292292
)

example/pubspec.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ packages:
133133
jpush_flutter:
134134
dependency: "direct dev"
135135
description:
136-
name: jpush_flutter
137-
url: "https://pub.dartlang.org"
138-
source: hosted
139-
version: "0.0.8"
136+
path: ".."
137+
relative: true
138+
source: path
139+
version: "0.0.11"
140140
js:
141141
dependency: transitive
142142
description:

example/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ dev_dependencies:
2626
flutter_test:
2727
sdk: flutter
2828

29-
jpush_flutter: ^0.0.8
30-
# path: ../
29+
jpush_flutter:
30+
path: ../
3131

3232
# For information on the generic Dart part of this file, see the
3333
# following page: https://www.dartlang.org/tools/pub/pubspec

ios/Classes/JPushPlugin.m

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,7 @@ - (void)clearAllNotifications:(FlutterMethodCall*)call result:(FlutterResult)res
295295
}
296296

297297
- (void)getLaunchAppNotification:(FlutterMethodCall*)call result:(FlutterResult)result {
298-
NSDictionary *notification;
299-
notification = [_launchNotification objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
300-
301-
if ([_launchNotification objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]) {
302-
UILocalNotification *localNotification = [_launchNotification objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
303-
notification = localNotification.userInfo;
304-
}
305-
result(notification);
298+
result(_launchNotification == nil ? @{}: _launchNotification);
306299
}
307300

308301
- (void)getRegistrationID:(FlutterMethodCall*)call result:(FlutterResult)result {
@@ -406,7 +399,22 @@ - (BOOL)application:(UIApplication *)application
406399

407400
if (launchOptions != nil) {
408401
_launchNotification = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
402+
_launchNotification = [self jpushFormatAPNSDic:_launchNotification.copy];
403+
}
404+
405+
if ([launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]) {
406+
UILocalNotification *localNotification = [launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
407+
NSMutableDictionary *localNotificationEvent = @{}.mutableCopy;
408+
localNotificationEvent[@"content"] = localNotification.alertBody;
409+
localNotificationEvent[@"badge"] = @(localNotification.applicationIconBadgeNumber);
410+
localNotificationEvent[@"extras"] = localNotification.userInfo;
411+
localNotificationEvent[@"fireTime"] = [NSNumber numberWithLong:[localNotification.fireDate timeIntervalSince1970] * 1000];
412+
localNotificationEvent[@"soundName"] = [localNotification.soundName isEqualToString:UILocalNotificationDefaultSoundName] ? @"" : localNotification.soundName;
409413

414+
if (@available(iOS 8.2, *)) {
415+
localNotificationEvent[@"title"] = localNotification.alertTitle;
416+
}
417+
_launchNotification = localNotificationEvent;
410418
}
411419
return YES;
412420
}
@@ -416,28 +424,13 @@ - (void)applicationDidEnterBackground:(UIApplication *)application {
416424
}
417425

418426
- (void)applicationDidBecomeActive:(UIApplication *)application {
419-
// _resumingFromBackground = NO;
420-
// Clears push notifications from the notification center, with the
421-
// side effect of resetting the badge count. We need to clear notifications
422-
// because otherwise the user could tap notifications in the notification
423-
// center while the app is in the foreground, and we wouldn't be able to
424-
// distinguish that case from the case where a message came in and the
425-
// user dismissed the notification center without tapping anything.
426-
// TODO(goderbauer): Revisit this behavior once we provide an API for managing
427-
// the badge number, or if we add support for running Dart in the background.
428-
// Setting badgeNumber to 0 is a no-op (= notifications will not be cleared)
429-
// if it is already 0,
430-
// therefore the next line is setting it to 1 first before clearing it again
431-
// to remove all
432-
// notifications.
433427
application.applicationIconBadgeNumber = 1;
434428
application.applicationIconBadgeNumber = 0;
435429
}
436430

437431
- (bool)application:(UIApplication *)application
438432
didReceiveRemoteNotification:(NSDictionary *)userInfo
439433
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
440-
// [self didReceiveRemoteNotification:userInfo];
441434

442435
[_channel invokeMethod:@"onReceiveNotification" arguments:userInfo];
443436
completionHandler(UIBackgroundFetchResultNoData);
@@ -461,28 +454,41 @@ - (void)application:(UIApplication *)application
461454

462455

463456

464-
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
465-
457+
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler API_AVAILABLE(ios(10.0)){
466458

467459
NSDictionary * userInfo = notification.request.content.userInfo;
468460
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
469461
[JPUSHService handleRemoteNotification:userInfo];
470-
[_channel invokeMethod:@"onReceiveNotification" arguments: userInfo];
462+
[_channel invokeMethod:@"onReceiveNotification" arguments: [self jpushFormatAPNSDic:userInfo]];
471463
}
472464

473-
474465
completionHandler(notificationTypes);
475466
}
476467

477-
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
468+
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler API_AVAILABLE(ios(10.0)){
478469
NSDictionary * userInfo = response.notification.request.content.userInfo;
479470
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
480471
[JPUSHService handleRemoteNotification:userInfo];
481-
// [[NSNotificationCenter defaultCenter] postNotificationName:@"kJPFOpenNotification" object:userInfo];
482-
[_channel invokeMethod:@"onOpenNotification" arguments: userInfo];
483-
472+
[_channel invokeMethod:@"onOpenNotification" arguments: [self jpushFormatAPNSDic:userInfo]];
484473
}
485474
completionHandler();
486475
}
487476

477+
- (NSMutableDictionary *)jpushFormatAPNSDic:(NSDictionary *)dic {
478+
NSMutableDictionary *extras = @{}.mutableCopy;
479+
for (NSString *key in dic) {
480+
if([key isEqualToString:@"_j_business"] ||
481+
[key isEqualToString:@"_j_msgid"] ||
482+
[key isEqualToString:@"_j_uid"] ||
483+
[key isEqualToString:@"actionIdentifier"] ||
484+
[key isEqualToString:@"aps"]) {
485+
continue;
486+
}
487+
extras[key] = dic[key];
488+
}
489+
NSMutableDictionary *formatDic = dic.mutableCopy;
490+
formatDic[@"extras"] = extras;
491+
return formatDic;
492+
}
493+
488494
@end

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: jpush_flutter
22
description: Offically supported JPush Flutter plugin.
3-
version: 0.0.10
3+
version: 0.0.11
44
author: huminios <[email protected]>
55
homepage: https://www.jiguang.cn
66

0 commit comments

Comments
 (0)