globalEvent
are used to listen for persistent events, such as changes in positioning information, gyroscopes, and so on. A global event is a secondary API that requires additional APIs to work with.
You can specify the event name as WXApplicationDidBecomeActiveEvent
or WXApplicationWillResignActiveEvent
to obtain application becoming foreground or background, so that you can pause your video or music at this time.
var globalEvent = weex.requireModule('globalEvent'); globalEvent.addEventListener("WXApplicationDidBecomeActiveEvent", function (e) { console.log("WXApplicationDidBecomeActiveEvent"); });
::: warning This feature only works on iOS and Android platforms, it doesn't work on Web. Obtain your weex platform on weex page :::
Android
Map<String,Object> params=new HashMap<>(); params.put("key","value"); mWXSDKInstance.fireGlobalEventCallback("geolocation", params);
iOS
[weexInstance fireGlobalEvent:@"geolocation" params:@{@"key":@"value"}];
Register global event.
var globalEvent = weex.requireModule('globalEvent'); globalEvent.addEventListener("geolocation", function (e) { console.log("get geolocation") });
Remove global event
var globalEvent = weex.requireModule('globalEvent'); globalEvent.removeEventListener("geolocation");