Can we access localStorage data in AppController.mm and AppActivity.java?

Hi,

I’m using Cocos2d-JS v3.6.1 and i have a problem on sharing data with cc.sys.localStorage.

  1. I need to store some data and pass to javascript in AppController.mm and AppActivity.java.
  2. I need to retrieve some data store with cc.sys.localStorage in javascript and use in AppController.mm and AppActivity.java.

For iOS, i have tried add this in AppController.mm but i can’t use the function as it is in c++

#import "cocos/storage/local-storage/LocalStorage.h"

For Android, i found Cocos2dxLocalStorage.java and import as

import com.cocos2dx.lib.Cocos2dxLocalStorage;

So how can i use the localStorage feature in AppController.mm and AppActivity.java?

Thanks!

If nobody gives you a solution maybe you could try calling a js function from the native code

Thanks for your suggestion.

I not familiar with either ways but can try as your suggestion.

The cc.sys.localStorage is working on native so we suppose can use it too.
But i can’t figure out how to do that yet.

I found a guide but the link is dead.
http://www.cocos2d-x.org/wiki/How_to_call_javascript_code_from_c++

@pandamicro
Can you please update the guide or help with this problem?

Thanks.

http://www.cocos2d-x.org/wiki/Invoking_Android_Java_methods_from_JavaScript

At the end there is a way to call from java to javascript. Idk if that will serve for IOS too.

P.D: Or if you need from explicitily from c++, maybe using jni from java will work but idk how to do it for IOS neither :smiley:

@alexgg

I found this from your link, but it seem the Objective-C don’t have something as call Javascript from Objective-C.
http://www.cocos2d-x.org/wiki/Invoking_Objective-C_methods_from_JavaScript

I’m still busy with something.
So i will dig deeper with that direction when i have the free time.

But i still hoping to see something easier to make the localStorage work as it already have the JSB and working in app.

Thanks for your info and really appreciated your help!