崩溃报告显示在第0行崩溃?

10

有人能帮忙解释一下这个崩溃报告吗?

没有异常名称或原因,回溯显示崩溃发生在包含崩溃的init方法的文件的第0行。 什么意思?

Incident Identifier: TODO
CrashReporter Key:   TODO
Hardware Model:      iPhone7,2
Process:         AppName [1112]
Path:            /private/var/mobile/Containers/Bundle/Application/2632C5D7-6A07-4002-A27B-D547E9A7345C/AppName.app/AppName
Identifier:      com.app.name
Version:         67
Code Type:       ARM-64
Parent Process:  launchd [1]

Date/Time:       2015-06-26 18:20:18 +0000
OS Version:      iPhone OS 8.3 (12F70)
Report Version:  104

Exception Type:  SIGTRAP
Exception Codes: TRAP_BRKPT at 0x10008c370
Crashed Thread:  0

Application Specific Information:
*** Terminating app due to uncaught exception '', reason: ''

崩溃线程的前几个符号化行:

0    AppName 0x000000010008c370 init (article, $metatype) (ArticleImageProvider.swift:0)
1    AppName 0x000000010006b0c4 shareArticleActivityViewController (article, track) (BasicArticleSharingController.swift:28)
2    AppName 0x0000000100063198 sharePressed () (DetailsViewController.swift:202)
3    AppName 0x00000001000600c8 sharePressed () (DetailsViewController.swift:200)
4    AppName 0x00000001000bfa8c sharePressed () (ContentNavView.swift:108)
5    AppName 0x000000010022f4b4 __55-[ASControlNode sendActionsForControlEvents:withEvent:]_block_invoke (ASControlNode.m:360)
6    AppName 0x000000010022f21c -[ASControlNode sendActionsForControlEvents:withEvent:] (ASControlNode.m:381)
7    AppName 0x000000010022e5b8 -[ASControlNode touchesEnded:withEvent:] (ASControlNode.m:191)
8    AppName 0x000000010026185c -[_ASDisplayView touchesEnded:withEvent:] (_ASDisplayView.mm:173)
9    UIKit 0x0000000187613d8c forwardTouchMethod + 260
10    UIKit 0x00000001874b0a2c -[UIWindow _sendTouchesForEvent:] + 696
11    UIKit 0x00000001874a9f68 -[UIWindow sendEvent:] + 680
12    UIKit 0x000000018747d18c -[UIApplication sendEvent:] + 260
13    UIKit 0x000000018771e324 _UIApplicationHandleEventFromQueueEvent + 15420
14    UIKit 0x000000018747b6a0 _UIApplicationHandleEventQueue + 1712

这里是一些代码:
// Where I attach the action to my button in ContentNavView
    shareButton.addTarget(self, action: "sharePressed", forControlEvents: ASControlNodeEvent.TouchUpInside)

/* snip */

// The implementation of ContentNavView#sharePressed()
func sharePressed() {
    delegate.sharePressed()
}


// The implementation of DetailsViewController#sharePressed()
func sharePressed() {
    if let cell = currentCell {
        let activityViewController = BasicArticleSharingController.shareArticleActivityViewController(cell.article)

        self.view.window?.rootViewController?.presentViewController(activityViewController, animated: true, completion: nil)
    }
}


// The implementation of BasicArticleSharingController#shareArticleActivityViewController(::) up to the initializer
class func shareArticleActivityViewController(article: Article, track: Bool = true) -> UIActivityViewController {
    var article = CoreDataManager.sharedManager.managedObjectContextForCurrentThread().objectWithID(article.objectID) as! Article

    let activities = [
        ArticleImageProvider(article: article), // Crash when calling this init?
        ArticleLinkProvider(article: article)
    ]

    /* snip */
}


// Implementation of the init that's crashing.  Apparently Swift only reports the class that crashes, not the line that crashes, so here's the implementation that I thought wasn't relevant.
final public class ArticleImageProvider: UIActivityItemProvider {

    let articleObjectID: NSManagedObjectID

    init(article: Article) {
        self.articleObjectID = article.objectID

        let article: Article = CoreDataManager.sharedManager.managedObjectContextForCurrentThread().objectWithID(article.objectID) as! Article

        let thumbnailCut = article.headlineImage?.cutWithShape(.Landscape)

        if let path = thumbnailCut?.localURL?.path {
            if let image = UIImage(contentsOfFile: path) {
                super.init(placeholderItem: image)
            }
            else {
                super.init(placeholderItem: UIImage())
            }
        } else {
            super.init(placeholderItem: UIImage())
        }
    }

    /* snip */
}

1
实际上,我觉得你对于在代码中寻找问题的位置相当了解。不过,你并没有向我们展示任何代码,所以很难看出你在问什么。除了“什么?”之外,似乎并没有其他问题。 - matt
@jycr753 这个崩溃报告已经被Crittercism解析了。无论如何,我认为Xcode在这里也没有帮助。 - Hyperbole
@matt 问题是是否有人能够帮助揭开崩溃报告的神秘面纱。我已经添加了回溯中提到的实现。 - Hyperbole
@matt,根据我的观察,崩溃发生在第0行,但是这一行并不存在。异常名称和原因都是空字符串。无论如何,我根据这个问题的答案(https://dev59.com/aIjca4cB1Zd3GeqPuk3s)添加了导致崩溃的方法的实现。 - Hyperbole
你进行了强制转换。你怎么知道它不会崩溃? - matt
显示剩余9条评论
1个回答

6

所以,我在这里学到了一些东西:

  1. objectWithID: 返回 NSManagedObject。就是这样。不能保证你发送该消息的对象将返回与接收方相同类型的对象,因此测试返回的对象是处理此问题的最安全方法。作为推论,通过管理对象减少或消除线程问题来限定NSFetchRequest的范围是一个极其重要的问题,可以完全消除这个问题。
  2. 编译后的Swift代码中信号陷阱较少,因此从苹果或Crittercism(通过NSThread#callStackSymbols或其他API)获取崩溃报告将始终返回与此处显示的相同的垃圾信息。你能做的最好的事情就是推断出可能导致崩溃的词法范围,并检查代码中是否存在任何可能的错误。在Swift成熟之前,我们只能这样做。
  3. 谨慎使用隐式解包可选项。

4
我决定勉强采用的另一个解决方案是,回到大多数情况下使用Objective C进行编码,直到Swift成熟。 - Casey Perkins

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接