Skip to content

Commit

Permalink
Implements #3 emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
Joao Caixinha committed Oct 2, 2015
1 parent a26654e commit b5b6938
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
44 changes: 41 additions & 3 deletions Pod/Classes/OrtcClient/OrtcClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,13 @@ - (void)opReceive:(NSString*) message {
[msgSentDict setObject:[NSNumber numberWithBool:YES] forKey:@"isMsgSent"];
[messagesBuffer setObject:msgSentDict forKey:messageId];
}


aMessage = [self escapeRecvChars:aMessage];

NSData *pos = [aMessage dataUsingEncoding:NSUTF8StringEncoding];
aMessage = [[NSString alloc] initWithData:pos encoding:NSNonLossyASCIIStringEncoding];

channelSubscription.onMessage(self, aChannel, aMessage);
}
}
Expand All @@ -1295,12 +1301,14 @@ - (NSString*)simulateJsonParse:(NSString*) str{
NSMutableString *ms = [NSMutableString string];
for(int i =0; i < [str length]; i++){
unichar ascii = [str characterAtIndex:i];

if(ascii > 128){ //unicode
[ms appendFormat:@"%@", [NSString stringWithCharacters:&ascii length:1]];
} else { //ascii
}else { //ascii
if(ascii == '\\'){
i = i + 1;
int next = [str characterAtIndex:i];

if(next == '\\'){
[ms appendString:@"\\"];
} else if(next == 'n'){
Expand All @@ -1315,15 +1323,45 @@ - (NSString*)simulateJsonParse:(NSString*) str{
[ms appendString:@"\r"];
} else if(next == 't'){
[ms appendString:@"\t"];
}
} else if(next == 'u'){
[ms appendString:@"\\u"];
}
} else {
[ms appendFormat:@"%c", ascii];
}
}
}
return ms;




return ms ;
}


- (NSString *) escapedUnicode:(NSString*)str
{
NSMutableString *uniString = [ [ NSMutableString alloc ] init ];
UniChar *uniBuffer = (UniChar *) malloc ( sizeof(UniChar) * [ str length ] );
CFRange stringRange = CFRangeMake ( 0, [ str length ] );

CFStringGetCharacters ( (CFStringRef)str, stringRange, uniBuffer );

for ( int i = 0; i < [ str length ]; i++ ) {
if ( uniBuffer[i] > 0x7e )
[ uniString appendFormat: @"\\u%04x", uniBuffer[i] ];
else
[ uniString appendFormat: @"%c", uniBuffer[i] ];
}

free ( uniBuffer );

NSString *retString = [ NSString stringWithString: uniString ];

return retString;
}


- (NSString*)generateId:(int) size
{
CFUUIDRef uuidRef = CFUUIDCreate(NULL);
Expand Down
1 change: 0 additions & 1 deletion Pod/Classes/OrtcClient/RealtimePushAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by iOSdev on 9/20/13.
// Copyright (c) 2013 Realtime.co All rights reserved.
//

#import <UIKit/UIKit.h>
#define NOTIFICATIONS_KEY @"Local_Storage_Notifications"

Expand Down

0 comments on commit b5b6938

Please sign in to comment.