_BSMachError while running Stanford's CS193p Smashtag app
Asked Answered
L

5

11

I downloaded the Smasthag demo app from course's site. Project builds fine (after small changes in Twitter, TwitterRequest etc. classes, because I use the latest Xcode 7b4) and works fine on simulator (I also had to add NSAppTransportSecurity key to info.plist), but not on a device - it doesn't fetch tweets . I tested it on both iPhone 6 with iOS 9 Public Beta and iPad 2 with iOS 8.4. Moreover, when app is running in the simulator and I change hashtag to search, whole tableView reloads with new tweets, but in the console I get this:

2015-07-23 03:24:15.560 Smashtag[25991:4344251] _BSMachError: (os/kern) invalid capability (20)
2015-07-23 03:24:15.560 Smashtag[25991:4344251] _BSMachError: (os/kern) invalid name (15)

App still runs fine, but this error bugs me. I couldn't fine anything about this _BSMachError in google (just one lonely Indonesian tweet). I can't also get why app doesn't fetch tweets on a device.

Laminous answered 23/7, 2015 at 11:47 Comment(2)
So I found out why app wasn't fetching tweets on a device. Actually it was fetching tweets, but couldn't convert them to its internal data structure. The problem was in String extension provided with Twitter class = asTwitterDate. It uses NSDateFormatter to get date from String. Extension implicitly assumes that formatters locale is English (which was true for the simulator) and my devices locales are Polish. Explicitly setting locale in code to English fixed the issue.Embellish
You are right. Changing locale in Tweet.swift fixed the issue. Thanks! Posted code to fix the issue.Enamor
E
5

To fix this issue you should set locale to en_US.

Change the private extension asTwitterDate in Tweet.swift to the following to fix issue on non en_US devices.

...
private extension String {
  var asTwitterDate: NSDate? {
    get {
        let dateFormatter = NSDateFormatter()
        dateFormatter.dateFormat = "EEE MMM dd HH:mm:ss Z yyyy"
        dateFormatter.locale = NSLocale(localeIdentifier: "en_US")
        let createdAt = dateFormatter.dateFromString(self)
        return createdAt
    }
  }
}

After this your application should load and show all data correctly.

Enamor answered 22/9, 2015 at 19:57 Comment(0)
E
8

This seems to be an iOS 9 Beta bug. It definitely is related to presentation and dismissal of UIKeyboard (the system one). And, at that it doesn't happen all the time.

It's harmless, just annoying. The bug will probably be resolved in the next beta since its in a core system object.

Ephrem answered 2/8, 2015 at 15:53 Comment(2)
I get this message and it has nothing to do with keyboard. It occurs on rotating the iOS 9 simulator. And i'm not in beta on either iOS 9 or XCode 7. So it will likely be at least a year before they fix this.Planogamete
I went back through my code and found it did happened during dismissing the keyboard.Phenacaine
C
5

You will need to add NSAppTransportSecurity as a dictionary and as the first child should be a bool named NSAllowsArbitraryLoads set to YES. Note that this opts out of NSAppTransportSecurity feature.

enter image description here

See the App Transport Security configuration notes here. Note that this documentation is brand new and has an error in it, if you want to opt out completely. The error is that the NSAllowsArbitraryLoads key isn't shown as a direct child of NSAppTransportSecurity.

Ideally what you should do is set the appropriate whitelisted domains and security settings.

https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/index.html

Caveman answered 24/7, 2015 at 19:34 Comment(2)
I have it, I mentioned it in my question.Embellish
Ah, I apologize. Actually I said this because Apple's documentation on NSAppTransportSecurity shows the plist hierarchy incorrectly. The allow NSAllowsArbitraryLoads key is one level deeper in the technote than it's supposed to be. I only realized when I wathed he WWDC video. I was getting those errors too, until I changed this appropriately. Perhaps it's a just a coincidence. developer.apple.com/library/prerelease/ios/technotes/…Caveman
E
5

To fix this issue you should set locale to en_US.

Change the private extension asTwitterDate in Tweet.swift to the following to fix issue on non en_US devices.

...
private extension String {
  var asTwitterDate: NSDate? {
    get {
        let dateFormatter = NSDateFormatter()
        dateFormatter.dateFormat = "EEE MMM dd HH:mm:ss Z yyyy"
        dateFormatter.locale = NSLocale(localeIdentifier: "en_US")
        let createdAt = dateFormatter.dateFromString(self)
        return createdAt
    }
  }
}

After this your application should load and show all data correctly.

Enamor answered 22/9, 2015 at 19:57 Comment(0)
C
0

I meet the same problem since I switch the keyboard form the system keyboard to self-defined keyboard.However it doesn`t affect my app running.

Cynicism answered 24/7, 2015 at 5:16 Comment(1)
I had the keyboard for textField set to Twitter keyboard, but after changing it to default keyboard the error is still present.Embellish
E
0

If there are any opaque attribute for any components in that control, just remove and it and use hidden attribute.

Example:

//invisibleTextView.alpha = 0.0f;
invisibleTextView.hidden = YES;
Effuse answered 22/5, 2016 at 11:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.