Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加getAlias方法 #212

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions android/src/main/java/com/jiguang/jpush/JPushPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public void onMethodCall(MethodCall call, Result result) {
getAllTags(call, result);
} else if (call.method.equals("setAlias")) {
setAlias(call, result);
} else if (call.method.equals("getAlias")) {
getAlias(call, result);
} else if (call.method.equals("deleteAlias")) {
deleteAlias(call, result);;
} else if (call.method.equals("stopPush")) {
Expand Down Expand Up @@ -236,6 +238,13 @@ public void setAlias(MethodCall call, Result result) {
JPushInterface.setAlias(registrar.context(), sequence, alias);
}

public void getAlias(MethodCall call, Result result) {
Log.d(TAG,"getAlias");
sequence += 1;
callbackMap.put(sequence, result);
JPushInterface.getAlias(registrar.context(), sequence);
}

public void deleteAlias(MethodCall call, Result result) {
Log.d(TAG,"deleteAlias:");

Expand Down
14 changes: 14 additions & 0 deletions ios/Classes/JPushPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
[self getAllTags:call result:result];
} else if([@"setAlias" isEqualToString:call.method]) {
[self setAlias:call result:result];
} else if([@"getAlias" isEqualToString:call.method]) {
[self getAlias:call result:result];
} else if([@"deleteAlias" isEqualToString:call.method]) {
[self deleteAlias:call result:result];
} else if([@"setBadge" isEqualToString:call.method]) {
Expand Down Expand Up @@ -290,6 +292,18 @@ - (void)setAlias:(FlutterMethodCall*)call result:(FlutterResult)result {
} seq: 0];
}

- (void)getAlias:(FlutterMethodCall*)call result:(FlutterResult)result {
JPLog(@"getAlias");
[JPUSHService getAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
if (iResCode == 0) {
result(@{@"alias": iAlias ?: @""});
} else {
NSError *error = [[NSError alloc] initWithDomain:@"JPush.Flutter" code:iResCode userInfo:nil];
result([error flutterError]);
}
} seq: 0];
}

- (void)deleteAlias:(FlutterMethodCall*)call result:(FlutterResult)result {
JPLog(@"deleteAlias:%@",call.arguments);
[JPUSHService deleteAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
Expand Down
29 changes: 23 additions & 6 deletions lib/jpush_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class JPush {
case "onReceiveMessage":
return _onReceiveMessage(call.arguments.cast<String, dynamic>());
case "onReceiveNotificationAuthorization":
return _onReceiveNotificationAuthorization(call.arguments.cast<String, dynamic>());
return _onReceiveNotificationAuthorization(
call.arguments.cast<String, dynamic>());
default:
throw new UnsupportedError("Unrecognized Event");
}
Expand Down Expand Up @@ -181,6 +182,23 @@ class JPush {
return result;
}

///
/// 获取 alias.
///
/// @param {String} alias
///
/// @param {Function} success = ({"alias":String}) => { }
/// @param {Function} fail = ({"errorCode":int}) => { }
///
Future<Map<dynamic, dynamic>> getAlias() async {
print(flutter_log + "getAlias:");

final Map<dynamic, dynamic> result =
await _channel.invokeMethod('getAlias');

return result;
}

///
/// 删除原有 alias
///
Expand Down Expand Up @@ -241,7 +259,7 @@ class JPush {
///
void clearNotification({@required int notificationId}) {
print(flutter_log + "clearNotification:");
_channel.invokeListMethod("clearNotification",notificationId);
_channel.invokeListMethod("clearNotification", notificationId);
}

///
Expand Down Expand Up @@ -283,19 +301,18 @@ class JPush {
return notification.toMap().toString();
}


/// 调用此 API 检测通知授权状态是否打开
Future<bool> isNotificationEnabled() async {
final Map<dynamic, dynamic> result = await _channel.invokeMethod('isNotificationEnabled');
final Map<dynamic, dynamic> result =
await _channel.invokeMethod('isNotificationEnabled');
bool isEnabled = result["isEnabled"];
return isEnabled;
}

/// 调用此 API 跳转至系统设置中应用设置界面
void openSettingsForNotification() {
void openSettingsForNotification() {
_channel.invokeMethod('openSettingsForNotification');
}

}

class NotificationSettingsIOS {
Expand Down