比如我现在先传递一个 object
,到底是用 onEventWithMap
还是用 onEventObject
呢?
官方的demo, 请问这两个方法区别是什么呢?
@ReactMethod
public void onEventWithMap(String eventId, ReadableMap map) {
Map<String, String> rMap = new HashMap<String, String>();
ReadableMapKeySetIterator iterator = map.keySetIterator();
while (iterator.hasNextKey()) {
String key = iterator.nextKey();
if (ReadableType.Array == map.getType(key)) {
rMap.put(key, map.getArray(key).toString());
} else if (ReadableType.Boolean == map.getType(key)) {
rMap.put(key, String.valueOf(map.getBoolean(key)));
} else if (ReadableType.Number == map.getType(key)) {
rMap.put(key, String.valueOf(map.getInt(key)));
} else if (ReadableType.String == map.getType(key)) {
rMap.put(key, map.getString(key));
} else if (ReadableType.Map == map.getType(key)) {
rMap.put(key, map.getMap(key).toString());
}
}
MobclickAgent.onEvent(context, eventId, rMap);
}
@ReactMethod
public void onEventObject(String eventID, ReadableMap property) {
Map<String, Object> map = new HashMap();
ReadableMapKeySetIterator iterator = property.keySetIterator();
while (iterator.hasNextKey()) {
String key = iterator.nextKey();
if (ReadableType.Array == property.getType(key)) {
map.put(key, property.getArray(key).toString());
} else if (ReadableType.Boolean == property.getType(key)) {
map.put(key, String.valueOf(property.getBoolean(key)));
} else if (ReadableType.Number == property.getType(key)) {
map.put(key, String.valueOf(property.getInt(key)));
} else if (ReadableType.String == property.getType(key)) {
map.put(key, property.getString(key));
} else if (ReadableType.Map == property.getType(key)) {
map.put(key, property.getMap(key).toString());
}
}
MobclickAgent.onEventObject(context, eventID, map);
}