Could not instantiate class named MKMapView
Asked Answered
T

9

166

I may be doing something really stupid here as I've done it before and it worked and now...

Created a new iPad project, in the details view I added a MKMapView, added the MapKit.framework to the project, added the property / etc. to the header. Go to run the project and get a SIGABRT with

****Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named MKMapView'**

I found http://mithin.in/2009/06/22/using-iphone-sdk-mapkit-framework-a-tutorial/ but, like I said, I've already added framework. What am I missing?

Tanaka answered 19/8, 2010 at 13:7 Comment(0)
H
381

I ran into this too, but I was able to get past it by following the instructions of step 2 in your link (thanks, by the way):

  1. Add the MapKit framework to the project. (Control + Click Frameworks folder -> Add -> Existing Frameworks)

I just searched for MapKit.framework, added it to the project, and the error went away.

I haven't added any map code yet (although I do have a MapViewDelegate connected in IB), but it's working fine so far!

Hooligan answered 25/8, 2010 at 2:25 Comment(4)
Glad it helped! I did finally get it working by doing the following: - Clean project - Reset device - Reboot machine Not sure which was necessary, but it works now :)Tanaka
Adding the MapKit framework also worked for me. My code brought up the map and everything worked fine.Amathist
If anyone runs into this problem with xcode 4.2, I was getting the error even though the framework was appearing in the Frameworks folder after I added it. I clicked on the target, then on Build Phases, and noticed that it was not in the Link Binary with Library section. Dragging it from the frameworks folder to the that section took care of the problem. Thanks for the hint,Muzzle
It's kind of sad, that it doesn't warn you when you dragging (from Iterface Builder) view that isn't linked in your project.Athwartships
R
31

Click on your project to bring the project settings. Under Targets, click your project, select from the upper toolbar "Build Phases". Under "Link binary With Libraries" tab, you will see the list of frameworks included in your project. Click the "+" button and add MapKit library from the shown list to your project.

Rightward answered 18/11, 2012 at 18:38 Comment(1)
Just want to mention that this issue is very tricky to detect, since the Apps work fine when launched in Debug mode from within XCode. The apps fail when launched directly on a device/emulator (for example: by tapping on the icon).Borgerhout
U
27

For Xcode 6.1:

  • Select your project
  • In general tab, look for Linked Frameworks and Libraries (last one)
  • Press + button
  • Search MapKit.framework
  • Finally add
Unhallowed answered 17/1, 2015 at 13:41 Comment(0)
M
18

Easy way!

Works above Xcode version 7.2

As far as I'm concerned selecting the MAPS from capabilities will automatically link your framework to your project all you have to do is check the Maps button in Capabilities -> Maps.

Heres the attached screenshot. Cheers!!

enter image description here

Mctyre answered 26/7, 2016 at 7:35 Comment(1)
This also works for Xcode version 8. After switching "Maps" on under "Capabilities", it indicates that the MapKit.framework will be linked. You can also confirm this by going to "Build Phases" and expanding the "Link Binary With Libraries" section. You should see the MapKit.framework there as well.Housetop
R
10

For xCode 4.2:

Click on your project name ->targets ->building Phase ->link binary with library 
  -> click on + sign ->select mapKit.framework ->click add
Recurrence answered 11/9, 2012 at 12:23 Comment(0)
Z
3

I noticed that I was getting this message (on top of the original one mentioned in this post) when I was building and running on the simulator:

ld: warning: ignoring file /Users/peter/programming/iPhone/iNspector/MapKit.framework/MapKit, file was built for unsupported file format which is not the architecture being linked (i386)

Then I just connected my iPhone, build and ran on the device, and the map worked.

So it seems that the MapKit framework cannot be compiled on the 386 architecture, it needs the device.

Zenger answered 30/11, 2011 at 2:56 Comment(0)
G
3

In regards to @futureshocked's input, I also came across the

Id: warning: ignoring file /blah.../MapKit, file was built for unsupported file format which is not the architecture being linked (i386)

issue.

**Check to make sure you didn't copy the MapKit framework into your local project directory when you added it to your project. I accidentally did this and XCode was giving me the above error. So I removed it from my project directory (in Finder), recompiled, and everything was normal again.

If you don't have the Framework in your project, go ahead and re-link as stated in the answer above.

Found a good tutorial on getting started with MapKit:
http://www.youtube.com/watch?v=X-3jM24EIGM&feature=related

Garlic answered 3/5, 2012 at 1:23 Comment(0)
I
3

I also received this error when trying to deploy to my 5.1 phone (with XC 4.5), even after changing my deployment target to be 5.1. Looks like the maps update wouldn't fly since I still had Google Maps on my phone. After updating my phone's OS, the exception disappeared.

Interurban answered 3/10, 2012 at 20:55 Comment(1)
Shouldn't it be sufficient to just remove the files with map definitions?Sharpen
C
3

Please import the WebKit at your Build Phases. You need to import the WebKit

Cicala answered 26/10, 2017 at 19:33 Comment(1)
What does WebKit have to do with MKMapView?Colosseum

© 2022 - 2024 — McMap. All rights reserved.