12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- //
- // WFCCTextMessageContent.m
- // WFChatClient
- //
- // Created by heavyrain on 2017/8/16.
- // Copyright © 2017年 WildFireChat. All rights reserved.
- //
- #import "WFCCLocationMessageContent.h"
- #import "WFCCIMService.h"
- #import "Common.h"
- #import "WFCCUtilities.h"
- @implementation WFCCLocationMessageContent
- - (WFCCMessagePayload *)encode {
- WFCCMessagePayload *payload = [[WFCCMessagePayload alloc] init];
- payload.contentType = [self.class getContentType];
- payload.searchableContent = self.title;
- payload.binaryContent = UIImageJPEGRepresentation(self.thumbnail, 0.67);
-
- NSMutableDictionary *dataDict = [NSMutableDictionary dictionary];
- [dataDict setObject:@(self.coordinate.latitude) forKey:@"lat"];
- [dataDict setObject:@(self.coordinate.longitude) forKey:@"long"];
- payload.content = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dataDict
- options:kNilOptions
- error:nil] encoding:NSUTF8StringEncoding];
- return payload;
- }
- - (void)decode:(WFCCMessagePayload *)payload {
- self.title = payload.searchableContent;
- self.thumbnail = [UIImage imageWithData:payload.binaryContent];
-
- NSError *__error = nil;
- NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:[payload.content dataUsingEncoding:NSUTF8StringEncoding]
- options:kNilOptions
- error:&__error];
- if (!__error) {
- double latitude = [dictionary[@"lat"] doubleValue];
- double longitude = [dictionary[@"long"] doubleValue];
- self.coordinate = CLLocationCoordinate2DMake(latitude, longitude);
- }
- }
- + (int)getContentType {
- return MESSAGE_CONTENT_TYPE_LOCATION;
- }
- + (int)getContentFlags {
- return WFCCPersistFlag_PERSIST_AND_COUNT;
- }
- + (instancetype)contentWith:(CLLocationCoordinate2D) coordinate title:(NSString *)title thumbnail:(UIImage *)thumbnail {
- WFCCLocationMessageContent *content = [[WFCCLocationMessageContent alloc] init];
- content.coordinate = coordinate;
- content.title = title;
- content.thumbnail = [WFCCUtilities generateThumbnail:thumbnail withWidth:180 withHeight:120];;
- return content;
- }
- + (void)load {
- [[WFCCIMService sharedWFCIMService] registerMessageContent:self];
- }
- - (NSString *)digest {
- return @"[位置]";
- }
- @end
|