Start a new topic

Call native code from Javascript

Call native code from Javascript


Hi,

I need to call some native function of Objective-C from ArchitectWorld Javascript file. There is a method from JS or I have to use callJavascript: method from iOS? Thanks

Hi Luca,
You can use the ObjC method -callJavaScript: to evaluate JS in the context of the current ARchitect World.
When you need to call from JS to ObjC, you can use our custom URL scheme 'architectsdk://'. Simply call 'document.location = architectsdk://theObjCMethodToCall?parameter1=foo&parameter2=bar'. You can append any parameter that you want. To receive those calls in your native application, set your WTArchitectView Delegate and impl. the method '-architectView:invokedURL:'. You get the complete URL and can then parse it to get the method name out of it. Afterwards simply do a if/else or something else to invoke the ObjC method you want.

Hope this helps

Best regards

Andreas

It's great, thank you :)

OK, for example, I want to load in Javascript a drawable when I'm near a GeoLocation. OK!

Now three buttons (in jQuery Mobile) will appear and these three buttons are linked to Objective-C using invokedURL method. iOS opens a view. When I will close the view, I want to see the ARchitect World without reload it. Is it possible? Maybe I can show the view over the architecView? 

Hi,
as long as you don't load the architect view again, the WTArchitectView will still be in the same state after a -stop / -start method call (presumed that you don't destroy all js object on stopping the architect view).

So don't call -loadArchitectWorldFromUrl in the -viewWillAppear / -viewDidAppear method of your view controller who manages the architect view.

Best regards

Andreas

Ok, it's perfect!

Last question: app seems reload, each time, 3D model. So document and data of the app will increase, that's why? Have I to destroy all ARObject before closing the app? 

 

EDIT:

I modified the JS file inserting the document.location.

I set the architectView object as delegate of WTArchitetcView, but it is not entering in invokedURL method...

 

ViewController.h

@interface W3DMViewController : UIViewController <WTArchitectViewDelegate>

 

ViewController.m

@implementation W3DMViewController

 

- (void)viewDidLoad

{

    ;

// Do any additional setup after loading the view, typically from a nib.

    if ( )

    {

        

        self.architectView = ;

        ;

        ;

        

        ; // 2

        

        NSURL *architectWorldUrl = ;

        NSLog(@"%@", architectWorldUrl);

        

        ;

        ; // 3

    

    }

    

}

 

-(void)viewWillAppear:(BOOL)animated

{

    ;

    

}

 

-(void)viewWillDisappear:(BOOL)animated

{

    ;

}

 

- (void)didReceiveMemoryWarning

{

    ;

    // Dispose of any resources that can be recreated.

    ;

}

 

 

- (void)architectView:(WTArchitectView *)architectView invokedURL:(NSURL *)url

{

    ;

}

 

@end

 

It doesn't stop :S

 

EDIT: I solved, I didn't see that was an error setting controller as delegate 
Login or Signup to post a comment