1. About Radio Monitoring
The first use is in Android, broadcast. It is mainly used to transfer data between 2 activity, send out a broadcast, interested in this broadcast to listen to it, to respond accordingly. The main is to pass the data, the trigger mechanism is better, with the global variable or a bit like, but there are differences in the use of occasions, such as the transfer of data between 2 activity, the activity of the life cycle of the global variables and the single case is not appropriate.
2.Android of broadcasting
Send broadcast:
Intent Intent = new Intent ("Our_ble_central_manager_notificaion_change_state"); Intent.putextra ("Key_old_state", oldstate); Intent.putextra ("Key_new_state", newstate); Mcontext.sendbroadcast (Intent);
Listen to the broadcast:
private void Registerblebroadcastreceiver () { Intentfilter intentfilter = new Intentfilter (); Intentfilter.addaction ("Our_ble_central_manager_notificaion_change_state"); This.mContext.registerReceiver (Mblebroadcastreceiver, intentfilter); } Private Blebroadcastreceiver mblebroadcastreceiver; Private class Blebroadcastreceiver extends Broadcastreceiver { @Override public void OnReceive (Context Context, Intent Intent) { String action = intent.getaction (); if (Action.equals ("Our_ble_central_manager_notificaion_change_state")) { } } }
Storing and extracting data via intent
3. IOS Notificationcenter
The names in iOS are different and are used almost as follows:
Send notification
Nsdictionary *dictionary = [[Nsdictionary alloc]init]; [[Nsnotificationcenter Defaultcenter] postnotificationname:@ "Our_ble_central_manager_notificaion_change_state"];
Listening:
[[Nsnotificationcenter Defaultcenter] Addobserver:cmios selector: @selector ( Blecentermanagernotificationchangestate:) name:@ "Our_ble_central_manager_notificaion_change_state" Object:nil] ;-(void) Blecentermanagernotificationchangestate: (nsnotification*) value{ log (" Blecentermanagernotificationchangestate "); Nsdictionary *dictionary = [value object]; NSNumber *oldstate = [dictionary objectforkey:key_old_state]; NSNumber *newstate = [dictionary objectforkey:key_new_state];}
Using dictionaries to pass data
4. Cocos2d a custom event in C + +
The old version of Cocos2d was also named after the notification, and the new one was changed.
Notification occurs:
Customclass retdata;director::getinstance ()->geteventdispatcher ()->dispatchcustomevent ("CbCC_BLE_CENTRAL_ Manager_notificaion_change_state ", &retdata);
Accept data:
_eventdispatcher->addcustomeventlistener ("Cbcc_ble_central_manager_notificaion_change_state", [This] ( Eventcustom* event) { Customclass *userdata = (Customclass *) Event->getuserdata (); });
You can pass data through a custom class.
It is convenient to transfer data between different scene,layer, triggering events. Lua's syntax is a little different, essentially the same.
http://www.waitingfy.com/archives/1692
About broadcast monitoring in Android iOS cocos2d