Bug 29191 - Problem with Xamarin.Forms Maps due to changes in iOS 8.10
Summary: Problem with Xamarin.Forms Maps due to changes in iOS 8.10
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.4.1
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-04-17 09:46 UTC by christian.falch
Modified: 2015-06-17 14:31 UTC (History)
9 users (show)

Tags: ac ios maps
Is this bug a regression?: ---
Last known good build:

Project with reproduction under iOS 8.10 (200.44 KB, application/zip)
2015-04-17 09:47 UTC, christian.falch

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description christian.falch 2015-04-17 09:46:32 UTC
**Error message:**
Event registration is overwriting existing delegate. Either just use events or your own delegate: Xamarin.Forms.Maps.iOS.MapDelegate MapKit.MKMapView+_MKMapViewDelegate

- Update Xamarin Studio and iOS (at least) with the latest releases from the beta channel
- Create a new Xamarin.Forms solution with at least support for iOS
- Add Xamarin.Forms.Maps using the nuget package manager
- Add initialization code in the AppDelegate (global::Xamarin.FormsMaps.Init ();)
- Add a map to the default Xamarin Forms page
- Run the project using the iOS simulator

Observe that you get the error message above.

**Note:** The reason for this seems to be that the Xamarin.Forms Maps Renderer for iOS sets both the RegionMoved event and the Map delegate in its OnElementChanged method. This causes a test to fail in Xamarin iOS that tries to prevent us from use events and delegates at the same time when handling map events.
Comment 1 christian.falch 2015-04-17 09:47:01 UTC
Created attachment 10800 [details]
Project with reproduction under iOS 8.10
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2015-04-17 16:38:36 UTC
Many thanks for the report!

I was able to reproduce this issue with:

But happily, it looks like the problem is fixed in the latest pre-release versions:

I updated these packages in both the "TestinMaps.iOS" and "TestinMaps" project in the attached test case,  and rebuilt the app. After that, the app ran without error and displayed a map (tested on iPhone 4, iOS 7.2.1 and iPhone 5s Simulator, iOS 8.1).

Be sure to let us know if the 1.4.2-pre2 versions do not address the problem when you try them. Thanks!
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2015-04-17 16:49:37 UTC
Typo correction: tested on iPhone 4, iOS 7.1.2
Comment 4 christian.falch 2015-04-20 11:57:23 UTC
I tried to upgrade the project, but still experienced the same problem (updated to of both Xamarin.Forms and Xamarin.Forms.Maps).

If you open the Assembly Browser and look up the class Xamarin.Forms.iOS.MapRenderer, you will see that it still sets both the RegionChanged event and the map delegate. This is the cause of the bug.

Comment 5 Brendan Zagaeski (Xamarin Team, assistant) 2015-04-20 12:42:51 UTC
Thanks for the investigation! In, I do indeed see assignments to both:

- The `MKMapView.RegionChanged` event.


- The `MKMapView.Delegate` property.

Both of these assignments appear in the `MapRenderer.OnElementChanged()` method.

In "Xamarin.Forms.Maps.iOS", I do _not_ see the same conflict. Instead I see:

- An assignment to the `MKMapView.RegionChanged` event, as before.


- A _new_ assignment to the `MKMapView.GetViewForAnnotation` property.

Both of these assignments use the `MKMapView.EnsureMKMapViewDelegate()` method behind the scenes, so I believe they should be compatible with each other. And that would explain why the app runs successfully on 1.4.2-pre2 in my quick tests. On the other hand, I might be missing some slightly more complicated usage pattern with the map that can still trigger this behavior using 1.4.2-pre2. Right now I've just been letting the map load on the simulator, and then zooming and panning around a little.

## Additional notes

It looks like this part of the code was adjusted to fix bug 25557. Admittedly, it sounds like there's a case where removing and re-adding Pins still does not work as expected related to bug 25557, so perhaps those code fixes still need further adjustment.

I will leave this bug open so that:

A. The QA team can double-check which behaviors they see with vs.


B. The Xamarin.Forms developers can chime in with any additional notes to confirm the expected behavior in and later.

Thanks again,
Xamarin Customer Support
Comment 6 Parmendra Kumar 2015-04-24 10:03:46 UTC
I have checked this issue and observed that
The application throw exception with Xamarin.Forms version and Xamarin.Forms.Maps

Screencast for the same: http://www.screencast.com/t/MnXhYAPvJ6r8

The application is working fine with Xamarin.Forms version and Xamarin.Forms.Maps

Screencast for the same: http://www.screencast.com/t/slyY6gocGQN

The application also wotking fine with Xamarin.Forms version