Skip to content

Commit

Permalink
Merge pull request #80 from AgoraIO/fix/getValue
Browse files Browse the repository at this point in the history
fix:xxValue is error
  • Loading branch information
LichKing-2234 committed May 17, 2021
2 parents 6b3c5ca + a47f374 commit e7ca33a
Showing 1 changed file with 50 additions and 35 deletions.
85 changes: 50 additions & 35 deletions ios/Classes/AgoraRtmPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ - (void)handleAgoraRtmClientMethod:(NSString *)name
}
else if ([@"setLog" isEqualToString:name]) {
NSInteger size = args[@"size"] != [NSNull null] ? [args[@"size"] integerValue] : 524288;
NSString *path = [[args objectForKey:@"path"] stringValue];
NSString *path = [self getString:[args objectForKey:@"path"]];
if (nil != path) {
NSString *dirPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
path = [NSString stringWithFormat:@"%@/%@", dirPath, path];
Expand All @@ -86,8 +86,8 @@ - (void)handleAgoraRtmClientMethod:(NSString *)name
});
}
else if ([@"login" isEqualToString:name]) {
NSString *token = [[args objectForKey:@"token"] stringValue];
NSString *userId = [[args objectForKey:@"userId"] stringValue];
NSString *token = [self getString:[args objectForKey:@"token"]];
NSString *userId = [self getString:[args objectForKey:@"userId"]];
[rtmClient.kit loginByToken:token user:userId completion:^(AgoraRtmLoginErrorCode errorCode) {
result(@{@"errorCode": @(errorCode)});
}];
Expand All @@ -98,7 +98,7 @@ - (void)handleAgoraRtmClientMethod:(NSString *)name
}];
}
else if ([@"renewToken" isEqualToString:name]) {
NSString *token = [[args objectForKey:@"token"] stringValue];
NSString *token = [self getString:[args objectForKey:@"token"]];
[rtmClient.kit renewToken:token completion:^(NSString *token, AgoraRtmRenewTokenErrorCode errorCode) {
result(@{@"errorCode": @(errorCode)});
}];
Expand All @@ -114,10 +114,10 @@ - (void)handleAgoraRtmClientMethod:(NSString *)name
}];
}
else if ([@"sendMessageToPeer" isEqualToString:name]) {
NSString *peerId = [[args objectForKey:@"peerId"] stringValue];
NSString *text = [[args objectForKey:@"message"] stringValue];
BOOL offline = [[args objectForKey:@"offline"] boolValue];
BOOL historical = [[args objectForKey:@"historical"] boolValue];
NSString *peerId = [self getString:[args objectForKey:@"peerId"]];
NSString *text = [self getString:[args objectForKey:@"message"]];
BOOL offline = [self getBool:[args objectForKey:@"offline"]];
BOOL historical = [self getBool:[args objectForKey:@"historical"]];
AgoraRtmSendMessageOptions *sendMessageOption = [[AgoraRtmSendMessageOptions alloc] init];
sendMessageOption.enableOfflineMessaging = offline;
sendMessageOption.enableHistoricalMessaging = historical;
Expand Down Expand Up @@ -163,7 +163,7 @@ - (void)handleAgoraRtmClientMethod:(NSString *)name
}];
}
else if ([@"getUserAttributes" isEqualToString:name]) {
NSString *userId = [[args objectForKey:@"userId"] stringValue];
NSString *userId = [self getString:[args objectForKey:@"userId"]];
[rtmClient.kit getUserAllAttributes:userId completion:^(NSArray<AgoraRtmAttribute *> * _Nullable attributes, NSString *userId, AgoraRtmProcessAttributeErrorCode errorCode) {
NSMutableDictionary *userAttributes = [[NSMutableDictionary alloc] init];
for (AgoraRtmAttribute *item in attributes) {
Expand All @@ -174,7 +174,7 @@ - (void)handleAgoraRtmClientMethod:(NSString *)name
}];
}
else if ([@"getUserAttributesByKeys" isEqualToString:name]) {
NSString *userId = [[args objectForKey:@"userId"] stringValue];
NSString *userId = [self getString:[args objectForKey:@"userId"]];
NSArray *keys = args[@"keys"] != [NSNull null] ? args[@"keys"] : nil;
[rtmClient.kit getUserAttributes:userId ByKeys:keys completion:^(NSArray<AgoraRtmAttribute *> * _Nullable attributes, NSString *userId, AgoraRtmProcessAttributeErrorCode errorCode) {
NSMutableDictionary *userAttributes = [[NSMutableDictionary alloc] init];
Expand All @@ -186,9 +186,9 @@ - (void)handleAgoraRtmClientMethod:(NSString *)name
}];
}
else if ([@"setChannelAttributes" isEqualToString:name]) {
NSString *channelId = [[args objectForKey:@"channelId"] stringValue];
NSString *channelId = [self getString:[args objectForKey:@"channelId"]];
NSArray *attributes = args[@"attributes"];
BOOL notify = [[args objectForKey:@"enableNotificationToChannelMembers"] boolValue];
BOOL notify = [self getBool:[args objectForKey:@"enableNotificationToChannelMembers"]];
NSMutableArray *rtmChannelAttributes = [[NSMutableArray alloc] init];
for (NSDictionary* item in attributes) {
AgoraRtmChannelAttribute *attribute = [[AgoraRtmChannelAttribute alloc] init];
Expand All @@ -203,9 +203,9 @@ - (void)handleAgoraRtmClientMethod:(NSString *)name
}];
}
else if ([@"addOrUpdateChannelAttributes" isEqualToString:name]) {
NSString *channelId = [[args objectForKey:@"channelId"] stringValue];
NSString *channelId = [self getString:[args objectForKey:@"channelId"]];
NSArray *attributes = args[@"attributes"];
BOOL notify = [[args objectForKey:@"enableNotificationToChannelMembers"] boolValue];
BOOL notify = [self getBool:[args objectForKey:@"enableNotificationToChannelMembers"]];
NSMutableArray *rtmChannelAttributes = [[NSMutableArray alloc] init];
for (NSDictionary* item in attributes) {
AgoraRtmChannelAttribute *attribute = [[AgoraRtmChannelAttribute alloc] init];
Expand All @@ -220,26 +220,26 @@ - (void)handleAgoraRtmClientMethod:(NSString *)name
}];
}
else if ([@"deleteChannelAttributesByKeys" isEqualToString:name]) {
NSString *channelId = [[args objectForKey:@"channelId"] stringValue];
NSString *channelId = [self getString:[args objectForKey:@"channelId"]];
NSArray *keys = args[@"keys"] != [NSNull null] ? args[@"keys"] : nil;
BOOL notify = [[args objectForKey:@"enableNotificationToChannelMembers"] boolValue];
BOOL notify = [self getBool:[args objectForKey:@"enableNotificationToChannelMembers"]];
AgoraRtmChannelAttributeOptions *channelAttributeOption = [[AgoraRtmChannelAttributeOptions alloc] init];
channelAttributeOption.enableNotificationToChannelMembers = notify;
[rtmClient.kit deleteChannel:channelId AttributesByKeys:keys Options:channelAttributeOption completion:^(AgoraRtmProcessAttributeErrorCode errorCode) {
result(@{@"errorCode": @(errorCode)});
}];
}
else if ([@"clearChannelAttributes" isEqualToString:name]) {
NSString *channelId = [[args objectForKey:@"channelId"] stringValue];
BOOL notify = [[args objectForKey:@"enableNotificationToChannelMembers"] boolValue];
NSString *channelId = [self getString:[args objectForKey:@"channelId"]];
BOOL notify = [self getBool:[args objectForKey:@"enableNotificationToChannelMembers"]];
AgoraRtmChannelAttributeOptions *channelAttributeOption = [[AgoraRtmChannelAttributeOptions alloc] init];
channelAttributeOption.enableNotificationToChannelMembers = notify;
[rtmClient.kit clearChannel:channelId Options:channelAttributeOption AttributesWithCompletion:^(AgoraRtmProcessAttributeErrorCode errorCode) {
result(@{@"errorCode": @(errorCode)});
}];
}
else if ([@"getChannelAttributes" isEqualToString:name]) {
NSString *channelId = [[args objectForKey:@"channelId"] stringValue];
NSString *channelId = [self getString:[args objectForKey:@"channelId"]];
[rtmClient.kit getChannelAllAttributes:channelId completion:^(NSArray<AgoraRtmChannelAttribute *> * _Nullable attributes, AgoraRtmProcessAttributeErrorCode errorCode) {
NSMutableArray<NSDictionary*> *channelAttributes = [NSMutableArray new];
for(AgoraRtmChannelAttribute *attribute in attributes) {
Expand All @@ -255,7 +255,7 @@ - (void)handleAgoraRtmClientMethod:(NSString *)name
}];
}
else if ([@"getChannelAttributesByKeys" isEqualToString:name]) {
NSString *channelId = [[args objectForKey:@"channelId"] stringValue];
NSString *channelId = [self getString:[args objectForKey:@"channelId"]];
NSArray *keys = args[@"keys"] != [NSNull null] ? args[@"keys"] : nil;
[rtmClient.kit getChannelAttributes:channelId ByKeys:keys completion:^(NSArray<AgoraRtmChannelAttribute *> * _Nullable attributes, AgoraRtmProcessAttributeErrorCode errorCode) {
NSMutableArray<NSDictionary*> *channelAttributes = [NSMutableArray new];
Expand All @@ -272,9 +272,9 @@ - (void)handleAgoraRtmClientMethod:(NSString *)name
}];
}
else if ([@"sendLocalInvitation" isEqualToString:name]) {
NSString *calleeId = [[args objectForKey:@"calleeId"] stringValue];
NSString *content = [[args objectForKey:@"content"] stringValue];
NSString *channelId = [[args objectForKey:@"channelId"] stringValue];
NSString *calleeId = [self getString:[args objectForKey:@"calleeId"]];
NSString *content = [self getString:[args objectForKey:@"content"]];
NSString *channelId = [self getString:[args objectForKey:@"channelId"]];
AgoraRtmLocalInvitation *invitation = [[AgoraRtmLocalInvitation new] initWithCalleeId:calleeId];
if (nil == invitation) return result(@{@"errorCode": @(-1)});
if (nil != content) {
Expand All @@ -291,9 +291,9 @@ - (void)handleAgoraRtmClientMethod:(NSString *)name
}];
}
else if ([@"cancelLocalInvitation" isEqualToString:name]) {
NSString *calleeId = [[args objectForKey:@"calleeId"] stringValue];
NSString *content = [[args objectForKey:@"content"] stringValue];
NSString *channelId = [[args objectForKey:@"channelId"] stringValue];
NSString *calleeId = [self getString:[args objectForKey:@"calleeId"]];
NSString *content = [self getString:[args objectForKey:@"content"]];
NSString *channelId = [self getString:[args objectForKey:@"channelId"]];
AgoraRtmLocalInvitation *invitation = rtmClient.localInvitations[calleeId];
if (nil == invitation) return result(@{@"errorCode": @(-1)});
if (nil != content) {
Expand All @@ -310,8 +310,8 @@ - (void)handleAgoraRtmClientMethod:(NSString *)name
}];
}
else if ([@"acceptRemoteInvitation" isEqualToString:name]) {
NSString *response = [[args objectForKey:@"response"] stringValue];
NSString *callerId = [[args objectForKey:@"callerId"] stringValue];
NSString *response = [self getString:[args objectForKey:@"response"]];
NSString *callerId = [self getString:[args objectForKey:@"callerId"]];
AgoraRtmRemoteInvitation *invitation = rtmClient.remoteInvitations[callerId];
if (nil == invitation) return result(@{@"errorCode": @(-1)});
if (response != nil) {
Expand All @@ -325,8 +325,8 @@ - (void)handleAgoraRtmClientMethod:(NSString *)name
}];
}
else if ([@"refuseRemoteInvitation" isEqualToString:name]) {
NSString *response = [[args objectForKey:@"response"] stringValue];
NSString *callerId = [[args objectForKey:@"callerId"] stringValue];
NSString *response = [self getString:[args objectForKey:@"response"]];
NSString *callerId = [self getString:[args objectForKey:@"callerId"]];
AgoraRtmRemoteInvitation *invitation = rtmClient.remoteInvitations[callerId];
if (nil == invitation) return result(@{@"errorCode": @(-1)});
if (response != nil) {
Expand All @@ -340,14 +340,14 @@ - (void)handleAgoraRtmClientMethod:(NSString *)name
}];
}
else if ([@"createChannel" isEqualToString:name]) {
NSString *channelId = [[args objectForKey:@"channelId"] stringValue];
NSString *channelId = [self getString:[args objectForKey:@"channelId"]];
RTMChannel *rtmChannel = [[RTMChannel alloc] initWithClientIndex:clientIndex channelId:channelId messenger:_messenger kit:rtmClient.kit];
if (nil == rtmChannel) return result(@{@"errorCode": @(-1)});
rtmClient.channels[channelId] = rtmChannel;
result(@{@"errorCode": @(0)});
}
else if ([@"releaseChannel" isEqualToString:name]) {
NSString *channelId = [[args objectForKey:@"channelId"] stringValue];
NSString *channelId = [self getString:[args objectForKey:@"channelId"]];
if (nil == rtmClient.channels[channelId]) return result(@{@"errorCode": @(-1)});
[rtmClient.kit destroyChannelWithId:channelId];
[rtmClient.channels removeObjectForKey:channelId];
Expand Down Expand Up @@ -378,10 +378,10 @@ - (void)handleAgoraRtmChannelMethod:(NSString *)name
}];
}
else if ([@"sendMessage" isEqualToString:name]) {
NSString *text = [[args objectForKey:@"message"] stringValue];
NSString *text = [self getString:[args objectForKey:@"message"]];
AgoraRtmMessage *message = [[AgoraRtmMessage new] initWithText:text];
BOOL offline = [[args objectForKey:@"offline"] boolValue];
BOOL historical = [[args objectForKey:@"historical"] boolValue];
BOOL offline = [self getBool:[args objectForKey:@"offline"]];
BOOL historical = [self getBool:[args objectForKey:@"historical"]];
AgoraRtmSendMessageOptions *sendMessageOption = [[AgoraRtmSendMessageOptions alloc] init];
sendMessageOption.enableOfflineMessaging = offline;
sendMessageOption.enableHistoricalMessaging = historical;
Expand Down Expand Up @@ -427,5 +427,20 @@ - (void)handleMethodCall:(FlutterMethodCall*)methodCall result:(FlutterResult)re
result(@{@"errorCode": @(-2), @"reason": FlutterMethodNotImplemented});
}
}
#pragma mark -
#pragma mark util
#pragma mark -
-(NSString *)getString:(id)obj{
if ([obj isEqual:[NSNull null]]) {
return nil;
}
return obj;
}
-(BOOL)getBool:(id)obj{
if ([obj isEqual:[NSNull null]]) {
return nil;
}
return obj;
}

@end

0 comments on commit e7ca33a

Please sign in to comment.