LoginSignup
3
3

More than 3 years have passed since last update.

Xcode11.4でMKMapViewを使うとクラッシュするかもしれない

Last updated at Posted at 2020-06-16

はじめに

Xcode 11.4 で MKMapView を使うとよくわからないクラッシュをした。。。

環境

  • Xcode 11.4 (11.3 と 11.5 も同様でした)

実機

  • iOS 13.1.3
  • iOS 13.4.1

ソース

Storyboard で MKMapView をのっけただけで ViewController には何も追記しない。

storyboard

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
}

現象

シミュレーターでは起動する。
実機をつないで Run でも起動する。

下記の場合クラッシュする。

  1. 実機をつないで Run
  2. Run 停止
  3. Run で実機にインストールしたアプリを起動
  4. クラッシュ!!

Xib でカスタム View をつくって MKMapView を置いても同様にクラッシュしました。
Xcode 11.5 にアップデートしてもクラッシュしました。。。

クラッシュログ

xception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0

Last Exception Backtrace:
0   CoreFoundation                  0x1814ae164 __exceptionPreprocess + 228
1   libobjc.A.dylib                 0x1811c2c1c objc_exception_throw + 59
2   CoreFoundation                  0x18139dbb8 +[NSException raise:format:] + 111
3   UIFoundation                    0x184b157fc UINibDecoderDecodeObjectForValue + 407
4   UIFoundation                    0x184b15b5c UINibDecoderDecodeObjectForValue + 1271
5   UIFoundation                    0x184ab0d50 -[UINibDecoder decodeObjectForKey:] + 311
6   UIKitCore                       0x185a935b8 -[UIView initWithCoder:] + 783
7   UIFoundation                    0x184b1593c UINibDecoderDecodeObjectForValue + 727
8   UIFoundation                    0x184ab0d50 -[UINibDecoder decodeObjectForKey:] + 311
9   UIKitCore                       0x185277694 -[UIRuntimeConnection initWithCoder:] + 175
10  UIFoundation                    0x184b1593c UINibDecoderDecodeObjectForValue + 727
11  UIFoundation                    0x184b15b5c UINibDecoderDecodeObjectForValue + 1271
12  UIFoundation                    0x184ab0d50 -[UINibDecoder decodeObjectForKey:] + 311
13  UIKitCore                       0x185272638 -[NSCoder+ 7239224 (UIIBDependencyInjectionInternal) _decodeObjectsWithSourceSegueTemplate:creator:sender:forKey:] + 491
14  UIKitCore                       0x185275200 -[UINib instantiateWithOwner:options:] + 1067
15  UIKitCore                       0x184f8bea4 -[UIViewController _loadViewFromNibNamed:bundle:] + 367
16  UIKitCore                       0x184f8c954 -[UIViewController loadView] + 179
17  UIKitCore                       0x184f8cc24 -[UIViewController loadViewIfRequired] + 187
18  UIKitCore                       0x184f8d30c -[UIViewController view] + 31
19  UIKitCore                       0x185630fd4 -[UIWindow addRootViewControllerViewIfPossible] + 179
20  UIKitCore                       0x1856306d0 -[UIWindow _updateLayerOrderingAndSetLayerHidden:actionBlock:] + 235
21  UIKitCore                       0x185631660 -[UIWindow _setHidden:forced:] + 367
22  UIKit                           0x1b80128a4 -[UIWindowAccessibility _orderFrontWithoutMakingKey] + 87
23  UIKitCore                       0x185642898 -[UIWindow _mainQueue_makeKeyAndVisible] + 51
24  UIKitCore                       0x185845174 -[UIWindowScene _makeKeyAndVisibleIfNeeded] + 203
25  UIKitCore                       0x184bcfc40 +[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] + 1327
26  UIKitCore                       0x1855f3da0 -[UIApplication _connectUISceneFromFBSScene:transitionContext:] + 971
27  UIKitCore                       0x1855f4124 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 331
28  UIKitCore                       0x185178a50 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 375
29  FrontBoardServices              0x18670ebec -[FBSSceneImpl _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 439
30  FrontBoardServices              0x186735190 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke.168 + 115
31  FrontBoardServices              0x186719aac -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 239
32  FrontBoardServices              0x186734e24 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke + 343
33  libdispatch.dylib               0x18114e33c _dispatch_client_callout + 19
34  libdispatch.dylib               0x1811510d4 _dispatch_block_invoke_direct + 263
35  FrontBoardServices              0x18675b2b4 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 47
36  FrontBoardServices              0x18675af60 -[FBSSerialQueue _queue_performNextIfPossible] + 431
37  FrontBoardServices              0x18675b4cc -[FBSSerialQueue _performNextFromRunLoopSource] + 31
38  CoreFoundation                  0x181429860 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 27
39  CoreFoundation                  0x1814297b4 __CFRunLoopDoSource0 + 83
40  CoreFoundation                  0x181428f68 __CFRunLoopDoSources0 + 295
41  CoreFoundation                  0x181423ca4 __CFRunLoopRun + 795
42  CoreFoundation                  0x181423660 CFRunLoopRunSpecific + 479
43  GraphicsServices                0x18b834604 GSEventRunModal + 163
44  UIKitCore                       0x1855f815c UIApplicationMain + 1943
45  MapTest                         0x10082458c 0x10081c000 + 34188
46  libdyld.dylib                   0x18129f1ec start + 3

たぶん UINibDecoderDecodeObjectForValue の辺でクラッシュしている。

回避策

Storyboard で MKMapView をのせるのはあきらめて下記のようにコードで記述する。

import UIKit
import MapKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        let mapView = MKMapView(frame: view.bounds)
        view.addSubview(mapView)
    }
}

これだと実機でも動作した:clap:

追記

Twitter で教えていただいた回避策。

MapKit.framework追加

MapKit.framework を追加するとクラッシュしませんでした:tada:

framework

addAnnotation

更によくわからないことに下記のようにするとクラッシュしない!!

import UIKit
import MapKit

class ViewController: UIViewController {

    @IBOutlet private weak var mapView: MKMapView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        mapView.addAnnotation(MKPointAnnotation())
    }
}

バグ報告はしていただけたそうです。(ありがたい:innocent:バグ報告ってなんとなくハードル高い。。。)

さいごに

原因はよくわからないけどちょっと前にあった Storyboard で UITextView を使うとクラッシュするのと同じようなやつかも??
それでもなんで Run 状態ならいけるんだろ??

Xcode のリリースノート見てみたけど特に Map 系は見当たらなかった。。。どなたか情報知ってたら教えて下さい:bow:

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3