174

Please note that this error message is pretty low level, so it crops up for different reasons in different scenarios. If you have a scenario that isn't mentioned in one of the answers below, please consider adding your situation as well, so maybe this could be a central answer for various situations that raise this error message.

Edit Nov 10, 2015 Also note, I marked my own answer as the answer, but that was before anyone else had posted. I guess none should really be marked as the answer, because as we've now seen below... this error doesn't have just one answer because it's so low level.

I'm running

  • iOS 9.0 Simulator
  • XCode 7.0

Everything was working fine yesterday.

Today, after a bunch of work on rotation related stuff, I started getting this error in my console output when I run the app in the Simulator and I rotate it.

_BSMachError: (os/kern) invalid capability (20)

_BSMachError: (os/kern) invalid name (15)

Screenshot for this issue - I've cleared my build folder, - I've cleaned the derived data folder, - I've reset the simulator.

I was working with

  • UIViewController viewWillLayoutSubviews
  • UIViewController viewWillTransitionToSize:...

I was also checking various 'Drawing' settings on the Attributes Inspector in IB.

I also made a utility category on UIView where I created a bunch of methods that create CGRect's and helps me assign frames to views.

Root View Controller

Root View Controller Settings

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177
Logicsaurus Rex
  • 3,172
  • 2
  • 18
  • 27
  • i am getting this error while working on BLE – Nex Mishra Nov 23 '15 at 15:42
  • 1
    I can't find a solution yet, and I'm also getting it whilst rotating. I also get a memory warning shortly afterwards sometimes, even though Xcode reports that only a small amount of memory is being used. Frustrating. – narco Jan 06 '16 at 23:49
  • 80
    Good think you redacted `MyFoodTracker` :P – Sam Soffes Feb 16 '16 at 22:18
  • 8
    Why is the MyFoodTracker crossed out with red line in the screenshot? – Marián Černý Feb 26 '16 at 12:46
  • I'm getting these errors also - from a couple of UIAlertActions that send the user either to the Mail app or to the App Store. These errors seem to only appear in the debug window of Xcode and doesn't seem to be affecting my app on any physical devices. But I am wondering if anyone has actually come across a situation where these errors actually cause a problem for end users on real devices?? – Monomeeth Mar 11 '16 at 12:25
  • All these scenarios are good and all, but what does it MEAN? – whoKnows Mar 27 '16 at 17:46
  • There are no answers on here that fix the issue for me. Please help! – Creagen Apr 10 '16 at 02:11
  • @whoKnows - "What does it mean?" I'm guessing the "invalid capability" is about as descriptive as something low level can get. Basically saying that you asked something of a code artifact that it's not capable of doing. For example, maybe in my case the "Clip Subviews" option isn't a valid choice for the object in question. – Logicsaurus Rex Apr 11 '16 at 14:44
  • 2
    @LogicsaurusRex "What does it mean?" is indeed not a useful question, but "Does it need fixing?" is maybe a better question (to which I'd like the answer). My app seems to work okay but is showing this error. I'd love to pin it down and fix it, but this is not a small app and finding it would cost me precious time. – vrwim Jun 09 '16 at 10:23

24 Answers24

144

Based on the https://forums.developer.apple.com/thread/15683:

Change "Localization native development region" in info.plist to United States instead of en.

Updated: Then you can revert these changes back.

Dmitry
  • 14,306
  • 23
  • 105
  • 189
blacharnia
  • 2,124
  • 2
  • 15
  • 16
  • 3
    It worked for me too. I then reverted the setting to "en" and error seems to not come back. – Skoua Nov 15 '15 at 14:46
  • It worked for me as a NEW instance of this error occurring. I posted the original post here and was getting this error because of one of the drawing checkboxes. It was gone for a long time, and now started cropping up again for some other unknown reason, and changing this actually fixed it... HOLY COW that's awesome. – Logicsaurus Rex Dec 03 '15 at 17:53
  • Mine is set to `ja`, not `en`. What should I do? Set it to `Japan`? – Nicolas Miari Jan 27 '16 at 08:27
  • I have not tried it with Japan but it is likely to resolve the issue. – blacharnia Jan 27 '16 at 12:54
  • I set it from "en" to "us" and it worked. Also setting it to "United States" or "United Kingdom" worked aswell. – MB_iOSDeveloper Feb 04 '16 at 09:36
  • 1
    This worked. However reverted back to en again and no error – Neo Feb 07 '16 at 08:32
  • 30
    I don't really like answers like this. Because it does not explain anything. Is it a bug on XCode? Is it our code positioning is wrong? Or what? – GeneCode May 29 '16 at 08:44
  • agree with @GeneCode – Sachin Rasane Nov 16 '18 at 13:22
66

I also ran into the _BSMachError console errors while deep linking into the Settings app on iOS 9 from a UIAlertController action. A dispatch_async solved my problem:

[aAlertVC addAction:[UIAlertAction actionWithTitle:@"Settings" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
    dispatch_async(dispatch_get_main_queue(), ^{
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    });
}]];
Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
19Craig
  • 843
  • 7
  • 11
  • 2
    This removed the console error for me, but the main lockup bug I was trying to fix that occurs at the same time was not helped – Jason Nov 25 '15 at 19:20
  • can probably generalize this answer, I got mine while performing segue in an uialertcontroller (almost the same code). Probably has to do with how the alertcontroller gets itself out of the picture. Solved my issue with dispatch_async also. – user3802077 Jan 05 '16 at 00:55
  • same issue here - specifically this occurs in 9.2 simulator when going to system settings from within my app via handler for UIAlertAction from within UIAlertController. When I rewrote code to UIAlertController instead of old UIAlertView the sim threw the same _BSMach errors (15,20). Did not occur on real device (ipad). Dispatch_async did make simulator happy. Is definitely related to UIAlertController. – Mike Kogan Feb 04 '16 at 20:38
  • same problem reared it's head again, this time not in the sim but on an ipad and NOT the sim. this time it was some code that rendered a view into a pdf context that caused the macherrors. again dispatch_async fixed it. I also verified that when this code executed without being invoked from the completion handler of a UIAlertAction in a UIAlertController this error does not occur. in both my cases the error was only visible in the XCode debug console and the app continued to execute correctly. None of the localization ideas suggested on this thread had any impact whatsoever to either scenario. – Mike Kogan Feb 05 '16 at 14:53
  • @Jason I had the same issue, it removed the console error message, but it still crashes. Did you manage to solve it somehow? – bp14 Jan 12 '17 at 16:11
33

Ok, I haven't pinned it down completely, but this will get you 99% of the way there. I'm using a third party map control from ESRI, and something about it doesn't like one of these drawing settings in the Attributes Inspector. I haven't tried each setting individually to see which setting it is, but when I turned all of them off (in the red box), everything worked like a charm, and I quit getting the error message above in the console. If and when I get time to nail it down to the precise setting or combination of settings, i'll update the answer.

enter image description here

Logicsaurus Rex
  • 3,172
  • 2
  • 18
  • 27
  • I think your answer is pretty good. However, I'd remove the bold text at the top. There's been a great many anonymous downvotes of answers lately, I doubt it's anything personal. – Jason D Oct 30 '15 at 14:07
  • what if i have to use one of these? – Zaraki Jun 07 '16 at 11:32
15

It's crazy but for me the solution was just to remove all breakpoints in the file where the error occured.

As for the cause? I think I accidentally hit a shortcut key to create a breakpoint in the current line. Because that was unintended I hit the same shortcut key again to delete it.

Oh my dear XCode...

august7cbfa7b7
  • 1,234
  • 1
  • 10
  • 13
  • This worked for me. One clue that this was the problem was that Xcode would break on lines that had no breakpoint. Then, on a different line I got the _BSMachErrors above. – didge Oct 04 '16 at 06:28
12

I was getting the same errors...

_BSMachError: (os/kern) invalid capability (20)
_BSMachError: (os/kern) invalid name (15)

I was calling openURL() from a UIAlertAction

alert.addAction(UIAlertAction(title: actionTitle, style: .Default) {
    UIApplication.shared.openURL(url)
 }

Deferring execution of the block until the next run loop fixed it...

alert.addAction(UIAlertAction(title: actionTitle, style: .Default) {
    OperationQueue.main.addOperation {UIApplication.shared.openURL(url)}
 }
Murray Sagal
  • 8,454
  • 4
  • 47
  • 48
9

I was getting the following when supplying new data:

> _BSMachError: (os/kern) invalid capability (20)
> _BSMachError: (os/kern) invalid name (15)

The error occurred when a button was used to supply new data. An NSTimer was used to refresh and update data upon returning from a performSegueWithIdentifier action. The timer was being activated and then invalidated immediately after use at return time. The MSMachError stopped when the timer was removed and - (void)viewWillAppear:(BOOL)animated and (void)viewDidAppear:(BOOL)animated were employed to perform the same function. This error started with upgrade to Xcode 7.

Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
Patt
  • 91
  • 1
6

I got this issue fixed by changing value of Localization native development region key to United Kingdom [or any Specific region] from its default value en present in info.plist of your project.

  1. Select Project Navigator
  2. Locate info.plist file present in ProjectNameTests folder.
  3. Change value of Localization native development region key to any specific region for eg. United Kingdom

Step 1 and 2

Step 3

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177
  • Yes, this fix sounds crazy, but it works. For me the app worked when Xcode 7.3.1 deployed to a tethered iPod touch 5th gen. But when first deployed from Xcode to a tethered iPad Air I encountered this `BSMachError`. Switching region to `United States` made the error go away. Yet another inexplicable Xcode mystery. – Basil Bourque Sep 03 '16 at 20:42
4

I also ran into the same problem in an NSOperation running on a background thread and I was still getting this error because a UIAlertController was still removing itself as another UI transaction was trying to take place. Modifying my code to this fixed the issue.

defer { 
    dispatch_async( dispatch_get_main_queue(),{
        completion()
    }) 
}

A lot of people don't know about defer -It lets the current scope complete and then runs after. Kinda neat.

Kellen Styler
  • 71
  • 1
  • 1
4

I did face the same error invalid capability (20) & invalid name (15). I tried the solutions as mentioned by others such as:

  • Localisation native development region key in info.plist
  • Changing drawing settings in the Attributes Inspector
  • Even altered ATS Exception Dictionary in info.plist

But none of those solutions solved my problem. Actually, I was trying to share some document but generating document would take some time and wanted to display an UIActivityIndicatorView to the user till the time document loads.

The solution for my error was:

//Create a alertView add UIActivityIndicatorView to it and present it in ViewController

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
//Call method 1 todo background process like getting data

dispatch_sync(dispatch_get_main_queue(), ^{
    //Call method 2 to update the UI
    [alert dismissViewControllerAnimated:YES completion:^(void){
        //My mistake was: I was calling method 2 over here to update the UI
        return;
    }];
});
});
Robert Longson
  • 118,664
  • 26
  • 252
  • 242
1218GG
  • 393
  • 3
  • 11
  • Excellent, worked for me! Important to know that updating the UI should be done in the dispatch_get_main_queue() – MkaysWork May 03 '16 at 09:22
3

Changing localization string from en to United States fixed this for me. However, make sure you clean after you change Info.plist. I've noticed that updates don't work when you just build after making plist changes. enter image description here

AppDever
  • 687
  • 1
  • 7
  • 17
2

In my case it was Little Snitch, it was blocking urls automatically.

Vaibhav Mishra
  • 11,384
  • 12
  • 45
  • 58
2

I could reproduce the error for me: If a make changes to one of the Views within a View that I am actually closing already (popViewControllerAnimated) I receive the error.

I am having a UINavigationButton action that makes an asynchronous task (POSTRequest). Before performing this request I set the customView of that button to an progress indicator. When coming back from the asynchronous call I dispatch to the main thread and reset the customView of that button. After that I am closing the view (popViewControllerAnimated).

This is the CORRECT code where the error does not appear:

/* right way, working without BSMachError */
@IBAction func sendRequest(sender: UIBarButtonItem) {
    /* setting the progress indicator as customView of the self.saveButton */
    self.showActivityIndicatory(self.saveButton)
    /* asynchronous REST call */
    UserDataManager.sharedInstance.requestFeedback(request, onCompletion: { error in
        dispatch_async(dispatch_get_main_queue(),{
        /* resetting the saveButton again to default by setting customView to nil */
        self.saveButton.customView = nil
        /* closing the view */
        self.navigationController!.popViewControllerAnimated(true)
      })
    })
}

What caused the error was switching lines: closing the view and then setting the customView to nil:

/* WRONG way, causing BSMachError */
@IBAction func sendRequest(sender: UIBarButtonItem) {
    /* setting the progress indicator as customView of the self.saveButton */
    self.showActivityIndicatory(self.saveButton)
    /* asynchronous REST call */
    UserDataManager.sharedInstance.requestFeedback(request, onCompletion: { error in
        dispatch_async(dispatch_get_main_queue(),{
        /* closing the view */
        self.navigationController!.popViewControllerAnimated(true)
        /* resetting the saveButton again to default by setting customView to nil */
        self.saveButton.customView = nil
      })
    })
}
Miaumi
  • 36
  • 4
2

This error started popping up after I added some observers:

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.keyboardWillHideOrShow(_:)), name:UIKeyboardWillShowNotification, object: nil)

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.keyboardWillHideOrShow(_:)), name:UIKeyboardWillHideNotification, object: nil)

The problem went away when I specified the class name instead of self:

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(MyClass.keyboardWillHideOrShow(_:)), name:UIKeyboardWillShowNotification, object: nil)

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(MyClass.keyboardWillHideOrShow(_:)), name:UIKeyboardWillHideNotification, object: nil)
Fook
  • 5,320
  • 7
  • 35
  • 57
2

I had the same error and none of the above applied to my problem. The problem appeared when I registered my view controller as an observer to a device orientation change, so the views could be resized and the drawings in the view could be made according to the new size of the view.

I had an outlet of a viewGraph which was a subclass of UIView in which I drew some graphics.In landscape mode the size of the viewGraph is larger than in portrait mode. So when the device changes its orientation the speedGraph needed to be redrawn.

The problem was, that I added several subviews to the speedGraph view, that contained graphics. These subviews needed to be laid out anew in the speedGraph view and then be redrawn. After the device changed its orientation I called viewDidAppear again to make the speedGraph view and all its subviews to be laid out anew and redraw themselves. Calling setNeedsDisplay for speedGraph doesn't work with orientation changes and subviews in a view.

What did I do wrong that caused the error to appear. In viewDidAppear I call a method which does some calculations and adds the subviews to the speedGraph view. The problem was that these subviews were created in the method and were added to the speedGraph view in this method. After leaving the method, the references to these subviews are, of course, deleted, but the subviews in the speedGraph view remain, since they are added. When the device changes, the subviews are created again and added to the speedGraph view, that already has these subviews, but can't find the references to these subviews anymore. The array of subviews of speedGraph view gets longer and longer with (i think) dangling subviews.

I solved the problem by defining the subviews that will be added to the speedGraph view as a class property and then do what needed to be done with the views inside this method. With this change the problem was gone.

MacUserT
  • 1,760
  • 2
  • 18
  • 30
2

Since we can post all situations returning the same error here, I felt free to post mine :). I got the Error when I changed privacy settings in the background. My app opened the settings app so the user can grant it permission to its photolibrary, when the permission switch is set, the app crashes with the mensioned error:

_BSMachError: (os/kern) invalid capability (20)
_BSMachError: (os/kern) invalid name (15)

This appears to be a forced restart of your app by the OS, because the user changed what your app can acces. So in my case it is an action of the OS who caused the error.

MQoder
  • 712
  • 8
  • 21
  • I got this one too. So this is actually not a bug. When the app is not connected to Xcode, nothing terrifying will happen. Thanks bro you might just save hours of my debugging time. – yuji May 19 '17 at 07:26
1

I got the same error message, because I assign a object property like @property (assign, nonatomic) NSNumber *aVariable;, fixed by changing to strong.

Allen
  • 6,745
  • 5
  • 41
  • 59
1

For what it's worth - it seems that a lot of situations throw this error. In my case, I had posted an alert when the user was dismissing a data entry form and data was in the form. I was able to eliminate the error by programmatically resigning the first responder from all applicable fields before unwinding the view controller.

JohnSF
  • 3,736
  • 3
  • 36
  • 72
  • This is the problem I'm having too, but since the view controller is dismissed by the back button from the navigation controller's navigation bar, `prepareForSegue()` doesn't get called and I don't know where to resign the first responder. – TimSim Jun 16 '16 at 22:42
1

I saw this when I pressed the Home button while a UIAlertController was displayed, which was dismissed when I relaunched the app. I added code to dismiss the UIAlertController in the appDelegate:

func applicationWillResignActive(application: UIApplication) {
  window?.rootViewController?.dismissViewControllerAnimated(false, completion: nil)
}

and the error message disappeared.

emrys57
  • 6,679
  • 3
  • 39
  • 49
1

The reason some developers doesn't get the error came back after changing from "Unites States" to "en" (or) other region, is that there is discrepancy between "Property list" and "Source code" views. It's probably Xcode bug. Whenever there is mismatch between these two views will throw this error, whatever it is "en" or "English". If you changed to "en" or "United States" for both views to be the same, will fix the issue.

Nay
  • 677
  • 1
  • 8
  • 14
1

I had this error when dismissing a popover via delegate. In the delegateMethod I triggered some GUI-Stuff. Putting the GUI-Stuff in the completionBlock of dismissViewControllerAnimated fixed it.

[myPopoverView dismissViewControllerAnimated:YES completion:^{ //GUI-Stuff}];
Yedy
  • 2,107
  • 1
  • 25
  • 30
1

I am a newb at this so take this for what it is worth.

What fixed this for me was changing the Simulated Metrics > Size > to iPad Full Screen. All of my views EXCEPT for the one that threw this error we set to iPad Full Screen. When I changed it, the error went away...

user1045302
  • 131
  • 1
  • 4
1

I got this error from:

var promptsArr =  StartRegAlerts() //Instance of the class

etc

func textFieldDidBeginEditing(textField: UITextField) {     
    switch textField.tag {
            case 0:
                alert(promptsArr.prompts["Name"]!)
            case 1:
                alert(promptsArr.prompts["CellPhone"]!)
            case 4:
                alert2(promptsArr.prompts["NUMBERCORRECT"]!)
                //alert(promptsArr.prompts["Wait4Pin"]!)

            default: break
            }
It only occurred for case 0 but not the other cases:
As a work around for now I commented out case 0 and that stopped the error.
I then changed  calling promptsArr.prompts by:

creating a new dictionary prompt and:

 override func viewDidAppear(animated: Bool) {
             prompt = promptsArr.prompts //
      }

and then used prompt in my alert calls. That fixed the problem.

So it appears that it is a timing issue.

Jeremy
  • 145
  • 1
  • 2
  • 13
  • I am afraid it only worked for awhile and then it reappeared - so commenting out case 1 and then calling that alert later seems to have resolved the issue. – Jeremy Sep 19 '16 at 07:10
0

with Xcode 8.1 and iOs 10 I also faced

_BSMachError: (os/kern) invalid capability (20)

_BSMachError: (os/kern) invalid name (15)

trying to override UiTraiCollection var to change at runtime the iPad’size classes to have two different interface layouts in Portraid and Landscape. It worked without any crash but generate our errors.

This was the "maliciuos" code:

override public var traitCollection: UITraitCollection {
    if UIDevice.currentDevice().userInterfaceIdiom == .Pad && UIDevice.currentDevice().orientation.isPortrait.boolValue {
        return UITraitCollection(traitsFromCollections:[UITraitCollection(horizontalSizeClass: .Compact), UITraitCollection(verticalSizeClass: .Regular)])
    }
    return super.traitCollection
}

The errors gone using override func viewWillTransition as alternative to detect interface rotation.

I hope this will be useful to someone

Swalsz
  • 33
  • 3
0

In my case the cause of the error was due to resizing. Built in IB. Anything that can change the size of a text field or similar for example changing line length can lead to this error I believe. In my case I simply had to adjust the text field size to cover all possibilities so it doesn't need to resize the box and conflict with something else.

Terence K
  • 41
  • 5