Integrating Google Mobile Analytics with MVVMCross

2019-08-08 17:04发布

The new Google Analytics SDK introduces a new subclass to UIViewController from which you have to inherit: GAITrackedViewController.

More info here: https://developers.google.com/analytics/devguides/collection/ios/v2/screens

This obviously clashes with MvxBindingTouchViewController, as you can only inherit from one class in C#.

What's the recommended way in getting this working?

1条回答
SAY GOODBYE
2楼-- · 2019-08-08 17:25

MvvmCross's MvxTouchViewController's is special...

MvvmCross's MvxBindingTouchViewController is even more special...

But these are only special in that they inherit from standard UIViewControllers (UIVIewController, UITableViewController, UITabBarController, etc) and then they add functionality for:

  • ViewModel construction and the ViewModel property at the Cirrious.MvvmCross layer
  • construction and storage of Bindings at the Cirrious.MvvmCross.Binding layer

Take a look at some examples:

In these you can hopefully see this involves a fair amount of cut and paste of code - although we do try to minimise it using extension methods. (If C# had multiple inheritance or mixins, we wouldn't need to do that - I'd love to have Mixins... but don't want multiple inhertitance ever!)

So.... if you want to add your own MvxXXXXXBindingViewController, then:

  1. take your base XXXXX class,
  2. inherit from it and add 'the stuff' to make an MvxXXXXViewController,
  3. then take your MvxXXXXXViewController and inherit from it again to make your MvxBindingXXXXXViewController
  4. publish to your blog and to a new GitHub repo so everyone else can piggyback off your hard work
  5. job done

Advanced notes:

  • If you want to see the same thing in Droid, see Insert a Monogame view inside MvvmCross monodroid Activity

  • The TabBarController is also interesting - it's got some additional methods

  • At some point 'soon' (first half of this year) we will create VeeThree and this will switch the MvxViewController's to a non generic format - this is because MonoTouch now recommends against using Generics on iOS base classes - Rolf says it's safe most of the time, but when it causes bugs they are 'heisenbugs'.

  • There is also some dead old-iOS code in the current classes (ViewDidUnload) - this code will be culled in VeeThree too.

查看更多
登录 后发表回答