Skip to content

Commit

Permalink
Fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Schreiner committed Jun 22, 2015
1 parent ece0364 commit 8a23530
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Connichiwa/CWUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
*/
+ (NSDictionary *)dictionaryFromJSONData:(NSData *)JSON;

+ (NSDictionary *)dictionaryFromJSONString:(NSString *)JSON;

/**
* Transforms a dictionary into a JSON data object. The resulting NSData object can then be decoded by using dictionaryFromJSONData: to retrieve the original dictionary. NSJSONSerialization is used, so the dictionary must contain only objects that can be serialized by NSJSONSerialization.
*
Expand Down
9 changes: 8 additions & 1 deletion Connichiwa/CWUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,18 @@ + (NSString *)escapedJSONStringFromDictionary:(NSDictionary *)dictionary

+ (NSDictionary *)dictionaryFromJSONData:(NSData *)JSON
{
if (JSON == nil) return [NSDictionary dictionary];
if (JSON == nil || [JSON length] < 1) return [NSDictionary dictionary];
return [NSJSONSerialization JSONObjectWithData:JSON options:0 error:nil];
}


+ (NSDictionary *)dictionaryFromJSONString:(NSString *)JSON
{
NSData *data = [JSON dataUsingEncoding:NSUTF8StringEncoding];
return [CWUtil dictionaryFromJSONData:data];
}


+ (NSData *)JSONDataFromDictionary:(NSDictionary *)dictionary
{
return [NSJSONSerialization dataWithJSONObject:dictionary options:NSJSONWritingPrettyPrinted error:nil];
Expand Down
8 changes: 4 additions & 4 deletions Connichiwa/CWWebLibraryManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ - (void)_registerJSCallbacks

__weak typeof(self) weakSelf = self;

self.webViewContext[@"nativeCallLocalInfo"] = ^(NSDictionary *info) {
[weakSelf _receivedFromView_localInfo:info];
self.webViewContext[@"nativeCallLocalInfo"] = ^(NSString *infoString) {
[weakSelf _receivedFromView_localInfo:infoString];
};

self.webViewContext[@"nativeCallLibraryDidLoad"] = ^{
Expand Down Expand Up @@ -251,12 +251,12 @@ - (void)_registerJSCallbacks
}


-(void)_receivedFromView_localInfo:(NSDictionary *)info {
-(void)_receivedFromView_localInfo:(NSString *)infoString {
NSDictionary *info = [CWUtil dictionaryFromJSONString:infoString];
if ([self.delegate respondsToSelector:@selector(webLibrarySentLocalInfo:)])
{
[self.delegate webLibrarySentLocalInfo:info];
}
// [self.appState setIdentifier:[info objectForKey:@"identifier"]];
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Connichiwa._onWebsocketOpen = function() {

Connichiwa.send("server", "_master_identification", { identifier: localInfo.identifier });

CWNativeBridge.callOnNative('nativeCallLocalInfo', localInfo);
CWNativeBridge.callOnNative('nativeCallLocalInfo', JSON.stringify(localInfo));
// Connichiwa.send("master", "localinfo", localInfo);

this._connectionAttempts = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Connichiwa._onWebsocketOpen = function() {
//Create local device
//This device might be extended by the native layer in the future
var localInfo = {
identifier : window._CW_NATIVE.identifier,
identifier : CWNativeBridge.isRunningNative() ? window._CW_NATIVE.identifier : CWUtil.createUUID(),
launchDate : Date.now() / 1000.0,
ppi : CWSystemInfo.PPI()
};
Expand Down

0 comments on commit 8a23530

Please sign in to comment.