UmengAnalyticsPlugin.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #import "UMMobClick/MobClick.h"
  2. #import "UmengAnalyticsPlugin.h"
  3. @implementation UmengAnalyticsPlugin
  4. + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  5. FlutterMethodChannel* channel = [FlutterMethodChannel
  6. methodChannelWithName:@"jitao.tech/umeng_analytics_plugin"
  7. binaryMessenger:[registrar messenger]];
  8. UmengAnalyticsPlugin* instance = [[UmengAnalyticsPlugin alloc] init];
  9. [registrar addMethodCallDelegate:instance channel:channel];
  10. }
  11. - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
  12. if ([@"init" isEqualToString:call.method]) {
  13. [self init:call result:result];
  14. } else if ([@"pageStart" isEqualToString:call.method]) {
  15. [self pageStart:call result:result];
  16. } else if ([@"pageEnd" isEqualToString:call.method]) {
  17. [self pageEnd:call result:result];
  18. } else if ([@"event" isEqualToString:call.method]) {
  19. [self event:call result:result];
  20. } else {
  21. result(FlutterMethodNotImplemented);
  22. }
  23. }
  24. - (void)init:(FlutterMethodCall*)call result:(FlutterResult)result {
  25. UMConfigInstance.appKey = call.arguments[@"iosKey"];
  26. UMConfigInstance.channelId = call.arguments[@"channel"];
  27. UMConfigInstance.bCrashReportEnabled = call.arguments[@"catchUncaughtExceptions"];
  28. [MobClick startWithConfigure:UMConfigInstance];
  29. [MobClick setLogEnabled:call.arguments[@"logEnabled"]];
  30. [MobClick setEncryptEnabled:call.arguments[@"encryptEnabled"]];
  31. [MobClick setLogSendInterval:[call.arguments[@"sessionContinueMillis"] doubleValue]];
  32. result([NSNumber numberWithBool:YES]);
  33. }
  34. - (void)pageStart:(FlutterMethodCall*)call result:(FlutterResult)result {
  35. NSString* viewName = call.arguments[@"viewName"];
  36. [MobClick beginLogPageView:viewName];
  37. result([NSNumber numberWithBool:YES]);
  38. }
  39. - (void)pageEnd:(FlutterMethodCall*)call result:(FlutterResult)result {
  40. NSString* viewName = call.arguments[@"viewName"];
  41. [MobClick endLogPageView:viewName];
  42. result([NSNumber numberWithBool:YES]);
  43. }
  44. - (void)event:(FlutterMethodCall*)call result:(FlutterResult)result {
  45. NSString* eventId = call.arguments[@"eventId"];
  46. NSString* label = call.arguments[@"label"];
  47. if (label == nil) {
  48. [MobClick event:eventId];
  49. } else {
  50. [MobClick event:eventId label:label];
  51. }
  52. result([NSNumber numberWithBool:YES]);
  53. }
  54. @end