Start a new topic
Solved

Capturing AR.logger data on iOS

Is there a good mechanism to send the contents of data logged to AR.logger to the Xcode console ? Or even better, to a method in an Objective C or swift class where we can capture the log data ?


Thanks! This looks great!

Good morning David,



something like this should do the trick:



in JavaScript:

  

myLoggingFunction: function(message)
{
	AR.logger.info(message);
	document.location = "architectsdk://myLoggingFunction?message=" + encodeURIComponent(message);
}

   


in Objective C:

   

- (void)architectView:(WTArchitectView *)architectView invokedURL:(NSURL *)URL
{
	NSDictionary *parameters = [URL URLParameter];
	if (parameters)
	{
		if ([[URL absoluteString] hasPrefix:@"architectsdk://myLoggingFunction"])
	}
	NSString *message = [parameters objectForKey:@"message"];
	NSLog(message);
}

   

DISCLAIMER: I did not run this code, so it might need some tweaking.


Here's a link to the documentation of the corresponding WTArchitectViewDelegate which defines the invokedURL method.




With the new API (release 6.1.0) it will look much neater:



in JavaScript:


   

myLoggingFunction: function(message)
{
	AR.logger.info(message);

	AR.platform.sendJSONObject({
		action: "myLoggingFunction",
		log: message
	});
}

  


in Objective C:

    

- (void)architectView:(WTArchitectView *)architectView receivedJSONObject:(NSDictionary *)jsonObject
{
	id actionObject = [jsonObject objectForKey:@"action"];

	if (actionObject && [actionObject isKindOfClass:[NSString class]])
	{
        	NSString *action = (NSString *)actionObject;
		if ([action isEqualToString:@"myLoggingFunction"])
		{
			id logObject = [jsonObject objectForKey:@"log"];

			if (logObject && [logObject isKindOfClass:[NSString class]])
			{
				NSString *log = (NSString *)logObject;
				NSLog(log);
			}
		}
	}
}

     


Documentation on the JSON based approach will follow upon releasing the new version of the SDK.



- Daniel




1 person likes this

Thanks Daniel,


The technique of using document.location (which I found further detail on here http://www.wikitude.com/developer/developer-forum/-/message_boards/message/467517) looks very promising!


I've got a rudimentary communications channel set up but If you have code examples handy of using this technique to create a generic bridging function back to native code I'd love to see it.


Thanks!

-Dave

Hi David,


I'm afraid the output of AR.logger cannot be captured in the native code or by any IDE, it simply outputs its messages straight to HTML which Xcode is oblivious to.


What you can do, is create your own logging function and call into the native code therein using document.location and the architectsdk:// protocol. Once you're in the native realm, you're free to call whatever logging mechanism you fancy.


I'd be happy to provide some code snippets, should you require any assistance with setting this communication channel up.


Also, we will be releasing a new mechanism to make calls to native code from JavaScript in the upcoming 6.1 release. It should be simpler to implement and more efficient.


- Daniel




1 person likes this
Login or Signup to post a comment