update fix demo to link native plugin

master
huangminlinux 6 years ago
parent d12d60222a
commit c80f769970

@ -1,4 +1,4 @@
## 0.0.10
## 0.0.11
iOS: 修复 getLaunchAppNotification 返回 null 的情况。
featurn: APNS 推送字段将 extras 字段移动到 notification.extras 中和 android 保持一致。

@ -7,7 +7,7 @@
```yaml
dependencies:
jpush_flutter: 0.0.10
jpush_flutter: 0.0.11
```
### 配置

@ -116,7 +116,22 @@ final JPush jpush = new JPush();
});
}),
new FlatButton(
child: new Text('getLaunchAppNotification\n'),
onPressed: () {
jpush.getLaunchAppNotification().then((map) {
setState(() {
debugLable = "getLaunchAppNotification success: $map";
});
})
.catchError((error) {
setState(() {
debugLable = "getLaunchAppNotification error: $error";
});
});
}),
new FlatButton(
child: new Text('applyPushAuthority\n'),
onPressed: () {
@ -271,22 +286,7 @@ final JPush jpush = new JPush();
jpush.clearAllNotifications();
}),
new FlatButton(
child: new Text('getLaunchAppNotification\n'),
onPressed: () {
jpush.getLaunchAppNotification().then((map) {
setState(() {
debugLable = "getLaunchAppNotification success: $map";
});
})
.catchError((error) {
setState(() {
debugLable = "getLaunchAppNotification error: $error";
});
});
}),
]
)

@ -133,10 +133,10 @@ packages:
jpush_flutter:
dependency: "direct dev"
description:
name: jpush_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.8"
path: ".."
relative: true
source: path
version: "0.0.11"
js:
dependency: transitive
description:

@ -26,8 +26,8 @@ dev_dependencies:
flutter_test:
sdk: flutter
jpush_flutter: ^0.0.8
# path: ../
jpush_flutter:
path: ../
# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

@ -295,14 +295,7 @@ static NSMutableArray<FlutterResult>* getRidResults;
}
- (void)getLaunchAppNotification:(FlutterMethodCall*)call result:(FlutterResult)result {
NSDictionary *notification;
notification = [_launchNotification objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if ([_launchNotification objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]) {
UILocalNotification *localNotification = [_launchNotification objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
notification = localNotification.userInfo;
}
result(notification);
result(_launchNotification == nil ? @{}: _launchNotification);
}
- (void)getRegistrationID:(FlutterMethodCall*)call result:(FlutterResult)result {
@ -406,7 +399,22 @@ didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (launchOptions != nil) {
_launchNotification = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
_launchNotification = [self jpushFormatAPNSDic:_launchNotification.copy];
}
if ([launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]) {
UILocalNotification *localNotification = [launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
NSMutableDictionary *localNotificationEvent = @{}.mutableCopy;
localNotificationEvent[@"content"] = localNotification.alertBody;
localNotificationEvent[@"badge"] = @(localNotification.applicationIconBadgeNumber);
localNotificationEvent[@"extras"] = localNotification.userInfo;
localNotificationEvent[@"fireTime"] = [NSNumber numberWithLong:[localNotification.fireDate timeIntervalSince1970] * 1000];
localNotificationEvent[@"soundName"] = [localNotification.soundName isEqualToString:UILocalNotificationDefaultSoundName] ? @"" : localNotification.soundName;
if (@available(iOS 8.2, *)) {
localNotificationEvent[@"title"] = localNotification.alertTitle;
}
_launchNotification = localNotificationEvent;
}
return YES;
}
@ -416,20 +424,6 @@ didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// _resumingFromBackground = NO;
// Clears push notifications from the notification center, with the
// side effect of resetting the badge count. We need to clear notifications
// because otherwise the user could tap notifications in the notification
// center while the app is in the foreground, and we wouldn't be able to
// distinguish that case from the case where a message came in and the
// user dismissed the notification center without tapping anything.
// TODO(goderbauer): Revisit this behavior once we provide an API for managing
// the badge number, or if we add support for running Dart in the background.
// Setting badgeNumber to 0 is a no-op (= notifications will not be cleared)
// if it is already 0,
// therefore the next line is setting it to 1 first before clearing it again
// to remove all
// notifications.
application.applicationIconBadgeNumber = 1;
application.applicationIconBadgeNumber = 0;
}
@ -437,7 +431,6 @@ didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- (bool)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
// [self didReceiveRemoteNotification:userInfo];
[_channel invokeMethod:@"onReceiveNotification" arguments:userInfo];
completionHandler(UIBackgroundFetchResultNoData);
@ -461,28 +454,41 @@ didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSe
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler API_AVAILABLE(ios(10.0)){
NSDictionary * userInfo = notification.request.content.userInfo;
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[JPUSHService handleRemoteNotification:userInfo];
[_channel invokeMethod:@"onReceiveNotification" arguments: userInfo];
[_channel invokeMethod:@"onReceiveNotification" arguments: [self jpushFormatAPNSDic:userInfo]];
}
completionHandler(notificationTypes);
}
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler API_AVAILABLE(ios(10.0)){
NSDictionary * userInfo = response.notification.request.content.userInfo;
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[JPUSHService handleRemoteNotification:userInfo];
// [[NSNotificationCenter defaultCenter] postNotificationName:@"kJPFOpenNotification" object:userInfo];
[_channel invokeMethod:@"onOpenNotification" arguments: userInfo];
[_channel invokeMethod:@"onOpenNotification" arguments: [self jpushFormatAPNSDic:userInfo]];
}
completionHandler();
}
- (NSMutableDictionary *)jpushFormatAPNSDic:(NSDictionary *)dic {
NSMutableDictionary *extras = @{}.mutableCopy;
for (NSString *key in dic) {
if([key isEqualToString:@"_j_business"] ||
[key isEqualToString:@"_j_msgid"] ||
[key isEqualToString:@"_j_uid"] ||
[key isEqualToString:@"actionIdentifier"] ||
[key isEqualToString:@"aps"]) {
continue;
}
extras[key] = dic[key];
}
NSMutableDictionary *formatDic = dic.mutableCopy;
formatDic[@"extras"] = extras;
return formatDic;
}
@end

@ -1,6 +1,6 @@
name: jpush_flutter
description: Offically supported JPush Flutter plugin.
version: 0.0.10
version: 0.0.11
author: huminios <h380108184@gmail.com>
homepage: https://www.jiguang.cn

Loading…
Cancel
Save