初投稿です。また、swift初心者です。(swift3)
緯度と経度、標高を画面に表示するアプリを作成したいのですが、うまく行きません。
Build Successedとなり、一度は起動するのですがその後強制的にアプリケーションが落ちてしまいます。
###エラーメッセージ
AppDelegateの
class AppDelegate: UIResponder, UIApplicationDelegate {
の部分にThread1:signal SIGABRTというエラーが出ます。
ただ、ここは全く編集していません。Main.Storyboardのみ編集してます。
ですので該当のソースコードの欄にはMain.Storyboadのコードを貼ります。
(指示いただけたら他のソースコードも貼ります。)
###該当のソースコード
Swift3
1 2import UIKit 3import CoreLocation 4 5class ViewController: UIViewController, CLLocationManagerDelegate { 6 7 var locationManager : CLLocationManager! 8 9 @IBOutlet weak var idoLabel: UILabel! 10 @IBOutlet weak var keidoLabel: UILabel! 11 @IBOutlet weak var hyoukouLabel: UILabel! 12 @IBOutlet weak var hanteiLabel: UILabel! 13 14 override func viewDidLoad(){ 15 super.viewDidLoad() 16 disabledLocationLabel() 17 locationManager.requestWhenInUseAuthorization() 18 locationManager.delegate = self 19 setupLocationService() 20 } 21 22 func setupLocationService(){ 23 locationManager.desiredAccuracy = kCLLocationAccuracyBest 24 locationManager.distanceFilter = 1 25 } 26 27 28 func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: 29 CLAuthorizationStatus) { 30 switch status{ 31 case .authorizedAlways, .authorizedWhenInUse : 32 //ロケーションの更新を開始 33 locationManager.startUpdatingLocation() 34 case .notDetermined: 35 //ロケーションの更新を停止する 36 locationManager.stopUpdatingLocation() 37 disabledLocationLabel() 38 default: 39 //ロケーションの更新を停止する 40 locationManager.stopUpdatingLocation() 41 disabledLocationLabel() 42 } 43 } 44 45 func disabledLocationLabel(){ 46 let msg = "位置情報の利用が許可されていません" 47 idoLabel.text = msg 48 keidoLabel.text = msg 49 hyoukouLabel.text = msg 50 } 51 52 func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){ 53 //locationの最後の値を取り出す 54 let locationData = locations.last 55 //緯度 56 if var ido = locationData?.coordinate.latitude{ 57 ido = round(ido*1000000)/1000000 58 idoLabel.text = String(ido) 59 } 60 //経度 61 if var keido = locationData?.coordinate.longitude{ 62 keido = round(keido*1000000)/1000000 63 keidoLabel.text = String(keido) 64 } 65 //標高 66 if var hyoukou = locationData?.altitude{ 67 hyoukou = round(hyoukou*100)/100 68 hyoukouLabel.text = String(hyoukou) + " m" 69 } 70 } 71 72 73 override func didReceiveMemoryWarning() { 74 super.didReceiveMemoryWarning() 75 // Dispose of any resources that can be recreated. 76 } 77 78 79} 80
###試したこと
ブレイクポイントをいろんなところに入れてみたのですが、初めの
override func viewDidLoad(){
の時点で実行されませんでした…。
###補足情報(言語/FW/ツール等のバージョンなど)
Swift version 3.1
Xcode 8.3.3
###追記
Exception Breakpointを追加して、止まっている箇所を調べてみて下さい。 >http://qiita.com/hidekuro/items/c851a9071441e666cb60
試しにやってみたところ、
class AppDelegate: UIResponder, UIApplicationDelegate {
のところにThread1:breakpoint1.1と表示されました。
また実行した時のデバッグエリアの内容ですが
2017-08-02 11:44:43.631 LocationTest[38593:7823380] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<LocationTest.ViewController 0x7fbb7560b2c0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key hanteilabel.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010e97db0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010b4ef141 objc_exception_throw + 48
2 CoreFoundation 0x000000010e97da59 -[NSException raise] + 9
3 Foundation 0x000000010b00500b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
4 UIKit 0x000000010bb5c994 -[UIViewController setValue:forKey:] + 87
5 UIKit 0x000000010bdc9a09 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x000000010e923e8d -[NSArray makeObjectsPerformSelector:] + 269
7 UIKit 0x000000010bdc83bf -[UINib instantiateWithOwner:options:] + 1856
8 UIKit 0x000000010bb62fc3 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x000000010bb638d9 -[UIViewController loadView] + 177
10 UIKit 0x000000010bb63c0a -[UIViewController loadViewIfRequired] + 195
11 UIKit 0x000000010bb6445a -[UIViewController view] + 27
12 UIKit 0x000000010ba2c98a -[UIWindow addRootViewControllerViewIfPossible] + 65
13 UIKit 0x000000010ba2d070 -[UIWindow _setHidden:forced:] + 294
14 UIKit 0x000000010ba3febe -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x000000010b9b937f -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4346
16 UIKit 0x000000010b9bf5e4 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1709
17 UIKit 0x000000010b9bc7f3 -[UIApplication workspaceDidEndTransaction:] + 182
18 FrontBoardServices 0x0000000112d7e5f6 FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24
19 FrontBoardServices 0x0000000112d7e46d -[FBSSerialQueue _performNext] + 186
20 FrontBoardServices 0x0000000112d7e7f6 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
21 CoreFoundation 0x000000010e923c01 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
22 CoreFoundation 0x000000010e9090cf __CFRunLoopDoSources0 + 527
23 CoreFoundation 0x000000010e9085ff __CFRunLoopRun + 911
24 CoreFoundation 0x000000010e908016 CFRunLoopRunSpecific + 406
25 UIKit 0x000000010b9bb08f -[UIApplication _run] + 468
26 UIKit 0x000000010b9c1134 UIApplicationMain + 159
27 LocationTest 0x000000010ae71047 main + 55
28 libdyld.dylib 0x000000010f34a65d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
となってました。よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー