Skip to content

Commit

Permalink
feat: 兼容iOS18
Browse files Browse the repository at this point in the history
  • Loading branch information
tangtaoit committed Oct 15, 2024
1 parent a89829f commit dd2ac0b
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 26 deletions.
15 changes: 10 additions & 5 deletions WuKongIMSDK/Classes/WKSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ + (WKSDK *)shared
- (NSMutableDictionary *)messageContentDict {
if(!_messageContentDict) {
_messageContentDict = [[NSMutableDictionary alloc] init];
[_messageContentDict setObject:[WKTextContent class] forKey:[NSString stringWithFormat:@"%li",(long)[WKTextContent contentType]]];
[_messageContentDict setObject:[WKImageContent class] forKey:[NSString stringWithFormat:@"%li",(long)[WKImageContent contentType]]];
[_messageContentDict setObject:[WKVoiceContent class] forKey:[NSString stringWithFormat:@"%li",(long)[WKVoiceContent contentType]]];
[_messageContentDict setObject:[WKCMDContent class] forKey:[NSString stringWithFormat:@"%li",(long)[WKCMDContent contentType]]];
[_messageContentDict setObject:[WKTextContent class] forKey:[NSString stringWithFormat:@"%li",[WKTextContent contentType].longValue]];
[_messageContentDict setObject:[WKImageContent class] forKey:[NSString stringWithFormat:@"%li",[WKImageContent contentType].longValue]];
[_messageContentDict setObject:[WKVoiceContent class] forKey:[NSString stringWithFormat:@"%li",[WKVoiceContent contentType].longValue]];
[_messageContentDict setObject:[WKCMDContent class] forKey:[NSString stringWithFormat:@"%li",[WKCMDContent contentType].longValue]];

}
return _messageContentDict;
Expand Down Expand Up @@ -204,7 +204,12 @@ - (NSString *)sdkVersion {


-(void) registerMessageContent:(Class)cls {
[self registerMessageContent:cls contentType:[cls contentType]];
if (cls && [cls respondsToSelector:@selector(contentType)]) {
NSNumber *contentType = [cls contentType];
[self registerMessageContent:cls contentType:contentType.integerValue];
} else {
NSLog(@"Error: Class does not respond to contentType or is nil");
}
}

-(void) registerMessageContent:(Class)cls contentType:(NSInteger)contentType {
Expand Down
1 change: 0 additions & 1 deletion WuKongIMSDK/Classes/model/WKMediaProto.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ NS_ASSUME_NONNULL_BEGIN
// 设置值到本地扩展字段内
-(void) setExtra:(id)value key:(NSString*)key;


@end

NS_ASSUME_NONNULL_END
4 changes: 2 additions & 2 deletions WuKongIMSDK/Classes/model/content/WKCMDContent.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ - (NSDictionary *)encodeWithJSON {

}

+(NSInteger) contentType {
return WK_CMD;
+(NSNumber*) contentType {
return @(WK_CMD);
}


Expand Down
4 changes: 2 additions & 2 deletions WuKongIMSDK/Classes/model/content/WKImageContent.m
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ - (NSDictionary *)encodeWithJSON {
return dataDict;
}

+(NSInteger) contentType {
return WK_IMAGE;
+(NSNumber*) contentType {
return @(WK_IMAGE);
}

- (NSString *)conversationDigest {
Expand Down
2 changes: 1 addition & 1 deletion WuKongIMSDK/Classes/model/content/WKMessageContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ typedef NS_ENUM(NSUInteger, WKMentionedType) {
你自定义的消息类型,在各个平台上需要保持一致
@return 正文类型
*/
+(NSInteger) contentType;
+(NSNumber*) contentType;


/// 实际获取到的contentType (这种情况只会一个content对象被指定多个contentType的时候,可以通过这个属性获取到真实的contentType)
Expand Down
14 changes: 7 additions & 7 deletions WuKongIMSDK/Classes/model/content/WKMessageContent.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ - (NSData *)encode {
if(self.realContentType !=0) {
[dataDict setObject:@(self.realContentType) forKey:@"type"];
}else {
[dataDict setObject:@([[self class] contentType]) forKey:@"type"];
[dataDict setObject:[[self class] contentType] forKey:@"type"];
}


Expand Down Expand Up @@ -353,19 +353,19 @@ -(void) encodeEntities:(NSMutableDictionary*)dict {
}

- (NSInteger)realContentType {
NSInteger contentType = [[self class] contentType];
if(contentType!=0) {
return contentType;
NSNumber *contentType = [[self class] contentType];
if(contentType) {
return contentType.integerValue;
}
if(self.contentDict && self.contentDict[@"type"] && [self.contentDict[@"type"] integerValue]!=0) {
return [self.contentDict[@"type"] integerValue];
}

return [[self class] contentType];
return [[self class] contentType].integerValue;
}

+(NSInteger) contentType {
return 0;
+(NSNumber*) contentType {
return @(0);
}

- (NSString *)conversationDigest {
Expand Down
4 changes: 2 additions & 2 deletions WuKongIMSDK/Classes/model/content/WKSignalErrorContent.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
@implementation WKSignalErrorContent


+(NSInteger) contentType {
return WK_SIGNAL_ERROR;
+(NSNumber*) contentType {
return @(WK_SIGNAL_ERROR);
}

- (NSString *)conversationDigest {
Expand Down
2 changes: 2 additions & 0 deletions WuKongIMSDK/Classes/model/content/WKTextContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ NS_ASSUME_NONNULL_BEGIN

@property(nonatomic,copy,nullable) NSString *format; // 内容格式 默认为普通文本 html,markdown



@end

NS_ASSUME_NONNULL_END
5 changes: 3 additions & 2 deletions WuKongIMSDK/Classes/model/content/WKTextContent.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ - (NSDictionary *)encodeWithJSON {
return @{@"content":self.content?:@"",@"format":self.format?:@""};
}

+(NSInteger) contentType {
return WK_TEXT;
+(NSNumber*) contentType {
return @(WK_TEXT);
}


- (NSString *)conversationDigest {
if([self.format isEqualToString:@"html"]) {
NSRegularExpression *regularExpretion=[NSRegularExpression regularExpressionWithPattern:@"<[^>]*>|\n"
Expand Down
4 changes: 2 additions & 2 deletions WuKongIMSDK/Classes/model/content/WKUnknownContent.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#import "WKConst.h"
@implementation WKUnknownContent

+(NSInteger) contentType {
return WK_UNKNOWN;
+(NSNumber*) contentType {
return @(WK_UNKNOWN);
}

- (NSString *)conversationDigest {
Expand Down
4 changes: 2 additions & 2 deletions WuKongIMSDK/Classes/model/content/WKVoiceContent.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ - (NSString *)thumbExtension {
return @".amr";
}

+(NSInteger) contentType {
return WK_VOICE;
+(NSNumber*) contentType {
return @(WK_VOICE);
}

- (NSString *)conversationDigest {
Expand Down

0 comments on commit dd2ac0b

Please sign in to comment.