微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ios – 崩溃报告指示第0行崩溃?

任何人都可以帮助揭开此崩溃报告的神秘面纱吗?

没有异常名称或原因,并且回溯显示在包含崩溃的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 */
}

解决方法

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

> objectWithID:返回NSManagedobject.而已.无法保证您发送该消息的对象将返回与接收方相同类型的对象,因此测试返回的对象是最安全的处理方法.作为一个必然结果,确定NSFetchRequests以减少或消除托管对象的线程问题是一个至关重要的问题,并将完全消除这个问题.>编译的Swift代码中只有更少的信号陷阱,因此从Apple或Crittercism(通过NSThread#callStackSymbols或其他一些API)获取崩溃报告将始终返回我在此处显示的相同垃圾.您可以做的最好的事情是推断出可能导致崩溃的词法范围,并为任何可能的错误梳理代码.在Swift成熟之前,我们不得不这样做.>谨慎使用隐式解包的选项.

原文地址:https://www.jb51.cc/iOS/331991.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐