Several errors when running my first iOS app - ios

I'm able to run the app initially (no visible errors), but when I input a number in the ageBox area and press the getAge button, I get several errors.
Here is the code:
import UIKit
class ViewController: UIViewController {
#IBOutlet var ageBox: UITextField!
#IBAction func getAge(sender: AnyObject) {
println(ageBox.text)
}
#IBOutlet var answerLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Here is the error I get:
2015-04-21 10:36:24.183 Cat Years[5284:2484424] Can't find keyplane
that supports type 4 for keyboard iPhone-PortraitChoco-NumberPad;
using 2705787216_PortraitChoco_iPhone-Simple-Pad_Default
2015-04-21 10:36:25.826 Cat Years[5284:2484424] Can't find keyplane
that supports type 4 for keyboard iPhone-PortraitChoco-NumberPad;
using 2705787216_PortraitChoco_iPhone-Simple-Pad_Default
5
2015-04-21 10:36:27.067 Cat Years[5284:2484424]
-[Cat_Years.ViewController getAgeButton:]: unrecognized selector sent to instance 0x7fc881e287f0
2015-04-21 10:36:27.078 Cat Years[5284:2484424] *** Terminating app
due to uncaught exception 'NSInvalidArgumentException', reason:
'-[Cat_Years.ViewController getAgeButton:]: unrecognized selector sent
to instance 0x7fc881e287f0'
*** First throw call stack:
(
0 CoreFoundation 0x00000001044c5c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000106030bb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001044cd0ad -[NSObject(NSObject)
doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010442313c forwarding + 988
4 CoreFoundation 0x0000000104422cd8 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000104d65da2 -[UIApplication
sendAction:to:from:forEvent:] + 75
6 UIKit 0x0000000104e7754a -[UIControl
_sendActionsForEvents:withEvent:] + 467
7 UIKit 0x0000000104e76919 -[UIControl touchesEnded:withEvent:] + 522
8 UIKit 0x0000000104db2998 -[UIWindow _sendTouchesForEvent:] + 735
9 UIKit 0x0000000104db32c2 -[UIWindow sendEvent:] + 682
10 UIKit 0x0000000104d79581 -[UIApplication sendEvent:] + 246
11 UIKit 0x0000000104d86d1c _UIApplicationHandleEventFromQueueEvent +
18265
12 UIKit 0x0000000104d615dc _UIApplicationHandleEventQueue + 2066
13 CoreFoundation 0x00000001043f9431
CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
14 CoreFoundation 0x00000001043ef2fd __CFRunLoopDoSources0 + 269
15 CoreFoundation 0x00000001043ee934 __CFRunLoopRun + 868
16 CoreFoundation 0x00000001043ee366 CFRunLoopRunSpecific + 470
17 GraphicsServices 0x00000001084aca3e GSEventRunModal + 161
18 UIKit 0x0000000104d64900 UIApplicationMain + 1282
19 Cat Years 0x00000001042c8007 main + 135
20 libdyld.dylib 0x0000000106788145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type
NSException
Any ideas?

Copied your code to a new project. Added a text box, switch, and label. Did the connections. Added constraints using "Add Missing Constraints". And it all worked (with no modification to your view controller code). Here is the link:
Project
The possibilities I can think of (based on errors I made when I started): (1) in changing connections while editing the storyboard I found that deleted controls are not automatically deleted in the xml file. Suggest you look in the connections editor to see if there are controls that you deleted. (2) do a "clean" to make sure.
Good luck

For the keyplane error,try this:
For reference:see this
iOS Simulator -> Hardware -> Keyboard -> Connect Hardware Keyboard
so that the entry is UNchecked then the software keyboard will be displayed once again.
For the NSInvalidArgumentException',try this:
#IBAction func getAge(sender: UIButton) {
println(ageBox.text)
}

Related

Thread:1 Signal SIGAGBRT

Why do I get a Thread:1 Signal SIGAGBRT within this code? I don't know what to change to fix the error. The application starts and as soon as I press the button the app cancels out and gives me an error.
import UIKit
class ViewController: UIViewController {
#IBOutlet var textFieldInput: UITextField!
#IBOutlet var laCelsius: UILabel!
#IBOutlet var laFahrenheit: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func btn(sender: UIButton) {
var c_out = 0.0
var f_out = 0.0
var inputValue = 0.0
let textInput = NSString(string: textFieldInput.text!)
inputValue = textInput.doubleValue
c_out = (inputValue-32)*5/9
f_out = inputValue * 1.8 + 32
self.laCelsius.text = NSString(format: "%3.2f" ,c_out) as String
self.laFahrenheit.text = NSString(format: "%3.2f" ,f_out) as String
}
}
this is the error code:
2016-09-22 14:15:51.669 DegreeCL[19045:1774964] -[DegreeCL.ViewController btnPressed:]: unrecognized selector sent to instance 0x7fa7bb643d40
2016-09-22 14:15:51.674 DegreeCL[19045:1774964] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DegreeCL.ViewController btnPressed:]: unrecognized selector sent to instance 0x7fa7bb643d40'
*** First throw call stack:
(
0 CoreFoundation 0x000000010de1dd85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010fbc1deb objc_exception_throw + 48
2 CoreFoundation 0x000000010de26d3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010dd6ccfa ___forwarding___ + 970
4 CoreFoundation 0x000000010dd6c8a8 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010e647a8d -[UIApplication sendAction:to:from:forEvent:] + 92
6 UIKit 0x000000010e7bae67 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x000000010e7bb143 -[UIControl _sendActionsForEvents:withEvent:] + 327
8 UIKit 0x000000010e7ba263 -[UIControl touchesEnded:withEvent:] + 601
9 UIKit 0x000000010e6ba99f -[UIWindow _sendTouchesForEvent:] + 835
10 UIKit 0x000000010e6bb6d4 -[UIWindow sendEvent:] + 865
11 UIKit 0x000000010e666dc6 -[UIApplication sendEvent:] + 263
12 UIKit 0x000000010e640553 _UIApplicationHandleEventQueue + 6660
13 CoreFoundation 0x000000010dd43301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x000000010dd3922c __CFRunLoopDoSources0 + 556
15 CoreFoundation 0x000000010dd386e3 __CFRunLoopRun + 867
16 CoreFoundation 0x000000010dd380f8 CFRunLoopRunSpecific + 488
17 GraphicsServices 0x00000001124b3ad2 GSEventRunModal + 161
18 UIKit 0x000000010e645f09 UIApplicationMain + 171
19 DegreeCL 0x000000010dc38412 main + 114
20 libdyld.dylib 0x000000011068592d start + 1
21 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The crucial information is
[DegreeCL.ViewController btnPressed:]: unrecognized selector sent to instance ...'
That means in Interface Builder there is somewhere a dead connection to an action btnPressed. Remove it.
You can search for btnPressed with ⇧⌘F.
SIGABRIT - signal is sent due to many reasons but in this case i think you have problem with Memory.
You should turn on All Exeptions with option of po $arg1 it will identify the error.
Select your button from interface builder, then select connection inspector from utilities and check that if you have extra connected action method should be there, remove it by clicking x and your issue will be solved!
It's should be btnPressed as per your crash log!

Swift button error on iOS app but not in playground

I am trying to learn swift to make free educational app for my country.
I know only the basics of programming and swift, but I am trying to understand iOS development.
I think I am having a problem with scope, but not sure what to do.
With didMoveToView being (the required) according to books I read, I can't compile and execute the code. So, when I run it in Xcode iOS App Project, my App crashes (even though it works in playground).
The code:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
class fooo {
static var bar = "hello world!"
#IBAction func hello_button(sender: AnyObject) {
print(fooo.bar)
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Below is the Crash log (Occurs on button touch):
2016-08-26 07:22:00.512 k[2074:37791] -[k.ViewController hello_button:]: unrecognized selector sent to instance 0x7aa2e670
2016-08-26 07:22:00.521 k[2074:37791] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[k.ViewController hello_button:]: unrecognized selector sent to instance 0x7aa2e670'
*** First throw call stack:
(
0 CoreFoundation 0x00200494 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01f17e02 objc_exception_throw + 50
2 CoreFoundation 0x0020a253 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0013f89d ___forwarding___ + 1037
4 CoreFoundation 0x0013f46e _CF_forwarding_prep_0 + 14
5 libobjc.A.dylib 0x01f2c0b5 -[NSObject performSelector:withObject:withObject:] + 84
6 UIKit 0x009f2e38 -[UIApplication sendAction:to:from:forEvent:] + 118
7 UIKit 0x009f2db7 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
8 UIKit 0x00b96f3b -[UIControl sendAction:to:forEvent:] + 79
9 UIKit 0x00b972d4 -[UIControl _sendActionsForEvents:withEvent:] + 433
10 UIKit 0x00b962c1 -[UIControl touchesEnded:withEvent:] + 714
11 UIKit 0x00a7352e -[UIWindow _sendTouchesForEvent:] + 1095
12 UIKit 0x00a745cc -[UIWindow sendEvent:] + 1159
13 UIKit 0x00a15be8 -[UIApplication sendEvent:] + 266
14 UIKit 0x009ea769 _UIApplicationHandleEventQueue + 7795
15 CoreFoundation 0x00112e5f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
16 CoreFoundation 0x00108aeb __CFRunLoopDoSources0 + 523
17 CoreFoundation 0x00107f08 __CFRunLoopRun + 1032
18 CoreFoundation 0x00107846 CFRunLoopRunSpecific + 470
19 CoreFoundation 0x0010765b CFRunLoopRunInMode + 123
20 GraphicsServices 0x04717664 GSEventRunModal + 192
21 GraphicsServices 0x047174a1 GSEventRun + 104
22 UIKit 0x009f0eb9 UIApplicationMain + 160
23 k 0x00012581 main + 145
24 libdyld.dylib 0x02935a25 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
You're right, the issue is scope (assuming you connected your button properly as others mentioned):
import UIKit
class ViewController: UIViewController {
class fooo {
var bar = "hello world!"
func mSayBar() { print(self.bar)}
}
var foo = fooo()
#IBAction func hello_button(sender: AnyObject) {
foo.mSayBar()
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
viewDidLoad is it's own local scope--it doesn't extend any further than the end brace " } "
After the first (millisecond?) everything declared in VDL is no longer alive; thus, it is best for initializing or calling, not declaring.
To declare global, just put everything in a new swift file, or put it outside ALL class scopes. Swift makes global scope easy (but be careful)
You said viewDidLoad is required, which is true, but only for setting up the program. Most of your logic / functions go outside of viewDidLoad
unrecognized selector sent to instance 0x7aa2e670 means that the button has been linked to an IBAction outlet that isn't defined in your code. Go to your ViewController's Storyboard mode, and right click the button in the subview list. Check if there is an outlet for the Touch Up Inside event and if it has the same name as the function in your code that you want to call (in your case it's hello_button.
Here's a picture if you didn't understand the above paragraph.

Error when trying to play audio in iPhone app

I am following udacity's course to try to learn how to make an iPhone app using xcode and swift. I am up to the part where I am playing an audio file when clicking a button in the app. Every time I click it, I get this error message:
in recordAudio
2015-04-05 14:42:18.124 Pitch Perfect[18544:1141273] -[Pitch_Perfect.PlaySoundsViewController slowAudio:]: unrecognized selector sent to instance 0x7f8174001760
2015-04-05 14:42:18.135 Pitch Perfect[18544:1141273] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Pitch_Perfect.PlaySoundsViewController slowAudio:]: unrecognized selector sent to instance 0x7f8174001760'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ab57a75 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010c6afbb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010ab5ed1d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010aab69dc ___forwarding___ + 988
4 CoreFoundation 0x000000010aab6578 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010b3eba22 -[UIApplication sendAction:to:from:forEvent:] + 75
6 UIKit 0x000000010b4f2e50 -[UIControl _sendActionsForEvents:withEvent:] + 467
7 UIKit 0x000000010b4f221f -[UIControl touchesEnded:withEvent:] + 522
8 UIKit 0x000000010b431b68 -[UIWindow _sendTouchesForEvent:] + 735
9 UIKit 0x000000010b432493 -[UIWindow sendEvent:] + 683
10 UIKit 0x000000010b3fefb1 -[UIApplication sendEvent:] + 246
11 UIKit 0x000000010b40c227 _UIApplicationHandleEventFromQueueEvent + 17700
12 UIKit 0x000000010b3e723c _UIApplicationHandleEventQueue + 2066
13 CoreFoundation 0x000000010aa8cc91 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x000000010aa82b5d __CFRunLoopDoSources0 + 269
15 CoreFoundation 0x000000010aa82194 __CFRunLoopRun + 868
16 CoreFoundation 0x000000010aa81bc6 CFRunLoopRunSpecific + 470
17 GraphicsServices 0x000000010eb2da58 GSEventRunModal + 161
18 UIKit 0x000000010b3ea580 UIApplicationMain + 1282
19 Pitch Perfect 0x000000010a61d42e top_level_code + 78
20 Pitch Perfect 0x000000010a61d46a main + 42
21 libdyld.dylib 0x000000010ce8b145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
here is the code I have to play the audio. I can't seem to figure out what is wrong. I have been following all of the steps exactly.
// PlaySoundsViewController.swift
// Pitch Perfect
import UIKit
import AVFoundation
class PlaySoundsViewController: UIViewController {
var audioPlayer:AVAudioPlayer!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
if var filePath = NSBundle.mainBundle().pathForResource("movie_quote",ofType: "mp3"){
var filePathUrl = NSURL.fileURLWithPath(filePath)
audioPlayer = AVAudioPlayer(contentsOfURL: filePathUrl, error: nil)
} else{
println("the filepath is empty")
}
}
#IBAction func playSlowAudio(sender: UIButton) {
// Play audio slowly
audioPlayer.play()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
Can someone please help me find the issue? I am very new to app development.
It seems you have a method called slowAudio: somewhere, but haven't implemented that method in your controller; maybe connected to a button in IB? Right-click on the button in the storyboard (or xib) to bring up the black window to see if there's a connection there to a method called slowAudio:. If there is, delete the connection by clicking on the little "x".

libc++abi.dylib: terminating with uncaught exception of type NSException on iOS 7.1

I am new to programming. I am going to learning iOS app development with the Apple new programming language Swift.
And I follow this site( https://developer.apple.com/swift/blog/?id=16 ) to start.
I copied the code from the video into my Xcode project. Anything was fine when I run the app in iOS 8.1 iOS simulator.
BUT I got exception while I choose iOS 7.1 iOS simulator. And I put the app into my iPhone 5S(iOS 7.1.2), it CRASHED.
Below is the code I copied from the video:
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var photoImageView: UIImageView!
let context = CIContext(options: nil)
#IBAction func applyFilter(sender: AnyObject) {
let inputImage = CIImage(image: photoImageView.image)
let randomColor = [kCIInputAngleKey: (Double(arc4random_uniform(314)) / 100)]
let filteredImage = inputImage.imageByApplyingFilter("CIHueAdjust",withInputParameters: randomColor)
let renderedImage = context.createCGImage(filteredImage, fromRect: filteredImage.extent())
photoImageView.image = UIImage(CGImage: renderedImage)
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Here is what I got from the console:
2014-11-03 16:17:30.645 njnj[2748:60b] -[CIImage imageByApplyingFilter:withInputParameters:]: unrecognized selector sent to instance 0x7fe4e3d165e0
2014-11-03 16:17:30.649 njnj[2748:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CIImage imageByApplyingFilter:withInputParameters:]: unrecognized selector sent to instance 0x7fe4e3d165e0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000106c8b495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010852799e objc_exception_throw + 43
2 CoreFoundation 0x0000000106d1c65d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000106c7cd8d ___forwarding___ + 973
4 CoreFoundation 0x0000000106c7c938 _CF_forwarding_prep_0 + 120
5 njnj 0x0000000106b934a0 _TFC4njnj14ViewController11applyFilterfS0_FPSs9AnyObject_T_ + 3648
6 njnj 0x0000000106b93a66 _TToFC4njnj14ViewController11applyFilterfS0_FPSs9AnyObject_T_ + 54
7 UIKit 0x000000010753af06 -[UIApplication sendAction:to:from:forEvent:] + 80
8 UIKit 0x000000010753af06 -[UIApplication sendAction:to:from:forEvent:] + 80
9 UIKit 0x000000010753aeb4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
10 UIKit 0x0000000107617880 -[UIControl _sendActionsForEvents:withEvent:] + 203
11 UIKit 0x0000000107616dc0 -[UIControl touchesEnded:withEvent:] + 530
12 UIKit 0x0000000107571d05 -[UIWindow _sendTouchesForEvent:] + 701
13 UIKit 0x00000001075726e4 -[UIWindow sendEvent:] + 925
14 UIKit 0x000000010754a29a -[UIApplication sendEvent:] + 211
15 UIKit 0x0000000107537aed _UIApplicationHandleEventQueue + 9579
16 CoreFoundation 0x0000000106c1ad21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
17 CoreFoundation 0x0000000106c1a5f2 __CFRunLoopDoSources0 + 242
18 CoreFoundation 0x0000000106c3646f __CFRunLoopRun + 767
19 CoreFoundation 0x0000000106c35d83 CFRunLoopRunSpecific + 467
20 GraphicsServices 0x000000010baf2f04 GSEventRunModal + 161
21 UIKit 0x0000000107539e33 UIApplicationMain + 1010
22 njnj 0x0000000106b9582e top_level_code + 78
23 njnj 0x0000000106b9586a main + 42
24 libdyld.dylib 0x0000000108ee55fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I hope someone can help me solve this problem.
(Sorry for my poor English)
Usually "unrecognized selector sent to instance" (resulting from -doesNotRecognizeSelector:) indicates a memory management issue, often an over-release of an object that is still referenced somewhere.
I suggest you run a debug build with memory debugging to triage your app's memory issues. I suggest you use ASan through recent versions of Xcode. If that's not an option, you can use malloc history with guard malloc, scribble, and NSZombies.

Swift app crashes with `unrecognized selector sent to instance` on CLLocationManager

Similar to many, many other questions on StackOverflow, I get a unrecognized selector sent to instance fault, when running my app. What makes my case different (I think) is that it is written in Swift and that the common reason is not the reason here.
In this question the solution is to set the "Custom Class" in the Identity Inspector for that view to the responding class. I checked this and this is the case (note that I did rename the class at some point, but it now is definitely set to "ViewController").
I include the stack trace below as well as the code for ViewController.swift. You can also find all of the code here. I managed to avoid this problem by starting fresh, which enabled me to solve my earlier question. This new trial can be found in this branch. But, I want to know what is wrong and solve this.
Some thought
One question that I couldn't answer successfully is whether CLLocationManagerDelegate needs some required methods? But because I got it to work in the other branch, I suspect it's not necessary.
2014-07-03 21:50:26.056 RowingTracker2[11416:60b] -[CLLocationManager requestWhenInUseAuthorization]: unrecognized selector sent to instance 0xa10c4a0
2014-07-03 21:50:26.059 RowingTracker2[11416:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CLLocationManager requestWhenInUseAuthorization]: unrecognized selector sent to instance 0xa10c4a0'
*** First throw call stack:
(
0 CoreFoundation 0x008831e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01e2a8e5 objc_exception_throw + 44
2 CoreFoundation 0x00920243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0087350b ___forwarding___ + 1019
4 CoreFoundation 0x008730ee _CF_forwarding_prep_0 + 14
5 RowingTracker2 0x00003352 _TFC14RowingTracker214ViewController11viewDidLoadfS0_FT_T_ + 738
6 RowingTracker2 0x000033a2 _TToFC14RowingTracker214ViewController11viewDidLoadfS0_FT_T_ + 34
7 UIKit 0x0102f33d -[UIViewController loadViewIfRequired] + 696
8 UIKit 0x0102f5d9 -[UIViewController view] + 35
9 UIKit 0x00f4f267 -[UIWindow addRootViewControllerViewIfPossible] + 66
10 UIKit 0x00f4f5ef -[UIWindow _setHidden:forced:] + 312
11 UIKit 0x00f4f86b -[UIWindow _orderFrontWithoutMakingKey] + 49
12 UIKit 0x00f5a3c8 -[UIWindow makeKeyAndVisible] + 65
13 UIKit 0x00f0abc0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 2097
14 UIKit 0x00f0f667 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
15 UIKit 0x00f23f92 -[UIApplication handleEvent:withNewEvent:] + 3517
16 UIKit 0x00f24555 -[UIApplication sendEvent:] + 85
17 UIKit 0x00f11250 _UIApplicationHandleEvent + 683
18 GraphicsServices 0x031fff02 _PurpleEventCallback + 776
19 GraphicsServices 0x031ffa0d PurpleEventCallback + 46
20 CoreFoundation 0x007feca5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
21 CoreFoundation 0x007fe9db __CFRunLoopDoSource1 + 523
22 CoreFoundation 0x0082968c __CFRunLoopRun + 2156
23 CoreFoundation 0x008289d3 CFRunLoopRunSpecific + 467
24 CoreFoundation 0x008287eb CFRunLoopRunInMode + 123
25 UIKit 0x00f0ed9c -[UIApplication _run] + 840
26 UIKit 0x00f10f9b UIApplicationMain + 1225
27 RowingTracker2 0x00008021 top_level_code + 97
28 RowingTracker2 0x0000805b main + 43
29 libdyld.dylib 0x024ff701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
ViewController.swift
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
#IBOutlet var mapview: MKMapView = nil
var locationmgr : CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
locationmgr = CLLocationManager()
locationmgr.delegate = self
locationmgr.requestWhenInUseAuthorization() ///< Offending line.
// mapview.showsUserLocation = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
As requestWhenInUseAuthorization method is only available on iOS 8 (according to Apple Documentation) you have to wrap it:
Swift code:
if (locationmgr.respondsToSelector(Selector("requestWhenInUseAuthorization"))) {
locationmgr.requestWhenInUseAuthorization()
}
And the same for Objective-C:
if ([locationmgr respondsToSelector:#selector(requestWhenInUseAuthorization)]) {
[locationmgr requestWhenInUseAuthorization];
}
This code won't run on iOS 7 and below - according the docs, requestWhenInUseAuthorization is only available on iOS 8:
Availability:
Available in iOS 8.0 and later.
Here is what I'm using to support the new core location method in iOS 7 with no errors:
SEL requestSelector = NSSelectorFromString(#"requestWhenInUseAuthorization");
if ([locationManager respondsToSelector:requestSelector]) {
[locationManager performSelector:requestSelector withObject:NULL];
}
Similarly, if you're seeing this error in relation to CLLocationManager, check that you are not attempting to use the authorizationStatus property on an iOS version prior to iOS14.
https://developer.apple.com/documentation/corelocation/cllocationmanager/3563952-authorizationstatus

Resources