代码之家  ›  专栏  ›  技术社区  ›  Dmitry Kurilo

iOS 9 CoreSpotlight API Xamarin索引崩溃()

  •  1
  • Dmitry Kurilo  · 技术社区  · 10 年前

    我有以下代码行:

    var attributes = new CSSearchableItemAttributeSet ();
    attributes.Title = "Title";
    attributes.ContentDescription = "Description";
    var item = new CSSearchableItem ("1", "space", attributes);
    
    if (CSSearchableIndex.IsIndexingAvailable) {
        CSSearchableIndex.DefaultSearchableIndex.Index (new [] { item }, (error) => {
            if (error != null) {
                Console.WriteLine("success");
            } else {
                Console.WriteLine("fail");
            }
        }); 
    }
    

    这给了我一种崩溃,“成功”分支永远无法到达:

    2015-09-18 23:24:30.136 Ross[189:3538] critical:    0   App_                                0x02f3a715 mono_handle_native_sigsegv + 240
    2015-09-18 23:24:30.137 Ross[189:3538] critical:    1   App_                                0x02f44437 mono_sigsegv_signal_handler + 150
    2015-09-18 23:24:30.138 Ross[189:3538] critical:    2   libsystem_platform.dylib            0x36cd485f _sigtramp + 42
    2015-09-18 23:24:30.139 Ross[189:3538] critical:    3   MobileCoreServices                  0x26b9be45 <redacted> + 12
    2015-09-18 23:24:30.140 Ross[189:3538] critical:    4   MobileCoreServices                  0x26b9be45 <redacted> + 12
    2015-09-18 23:24:30.141 Ross[189:3538] critical:    5   MobileCoreServices                  0x26ba500d _UTTypeCopyPedigree + 60
    2015-09-18 23:24:30.142 Ross[189:3538] critical:    6   CoreSpotlight                       0x2540287f <redacted> + 170
    2015-09-18 23:24:30.142 Ross[189:3538] critical:    7   CoreSpotlight                       0x25416123 <redacted> + 130
    2015-09-18 23:24:30.143 Ross[189:3538] critical:    8   CoreSpotlight                       0x25414f03 <redacted> + 54
    2015-09-18 23:24:30.144 Ross[189:3538] critical:    9   libdispatch.dylib                   0x36b40ed7 <redacted> + 10
    2015-09-18 23:24:30.145 Ross[189:3538] critical:    10  libdispatch.dylib                   0x36b4b04f <redacted> + 1762
    2015-09-18 23:24:30.145 Ross[189:3538] critical:    11  libdispatch.dylib                   0x36b4402f <redacted> + 282
    2015-09-18 23:24:30.146 Ross[189:3538] critical:    12  libdispatch.dylib                   0x36b4c3dd <redacted> + 400
    2015-09-18 23:24:30.146 Ross[189:3538] critical:    13  libdispatch.dylib                   0x36b4c24b <redacted> + 94
    2015-09-18 23:24:30.147 Ross[189:3538] critical:    14  libsystem_pthread.dylib             0x36cd5e29 _pthread_wqthread + 1024
    2015-09-18 23:24:30.148 Ross[189:3538] critical:    15  libsystem_pthread.dylib             0x36cd5a18 start_wqthread + 8
    2015-09-18 23:24:30.149 Ross[189:3538] critical: 
    =================================================================
    Got a SIGSEGV while executing native code. This usually indicates
        a fatal error in the mono runtime or one of the native libraries 
        used by your application.
        =================================================================
    

    更新1 模拟器给出了更详细的崩溃:

    2015-09-18 23:51:05.352 Ross[24134:2660436] critical:   0   App_                                0x0026b037 mono_handle_native_sigsegv + 311
    2015-09-18 23:51:05.353 Ross[24134:2660436] critical:   1   App_                                0x00297616 mono_sigsegv_signal_handler + 214
    2015-09-18 23:51:05.353 Ross[24134:2660436] critical:   2   libsystem_platform.dylib            0x0413e03b _sigtramp + 43
    2015-09-18 23:51:05.353 Ross[24134:2660436] critical:   3   ???                                 0xffffffff 0x0 + 4294967295
    2015-09-18 23:51:05.354 Ross[24134:2660436] critical:   4   MobileCoreServices                  0x05651b78 _UTTypeIdentifierIsDynamic + 25
    2015-09-18 23:51:05.354 Ross[24134:2660436] critical:   5   MobileCoreServices                  0x0565da01 _UTTypeCopyPedigree + 91
    2015-09-18 23:51:05.354 Ross[24134:2660436] critical:   6   CoreSpotlight                       0x032dcbfb -[CSSearchableItem(Internal) standardizeAttributes] + 213
    2015-09-18 23:51:05.355 Ross[24134:2660436] critical:   7   CoreSpotlight                       0x032f73db -[CSSearchableIndex _standardizeItems:] + 167
    2015-09-18 23:51:05.355 Ross[24134:2660436] critical:   8   CoreSpotlight                       0x032f5928 __161-[CSSearchableIndex indexSearchableItems:deleteSearchableItemsWithIdentifiers:clientState:clientStateName:protectionClass:forBundleID:options:completionHandler:]_block_invoke + 60
    2015-09-18 23:51:05.355 Ross[24134:2660436] critical:   9   libdispatch.dylib                   0x03dd8a7f _dispatch_call_block_and_release + 15
    2015-09-18 23:51:05.356 Ross[24134:2660436] critical:   10  libdispatch.dylib                   0x03df66fd _dispatch_client_callout + 14
    2015-09-18 23:51:05.356 Ross[24134:2660436] critical:   11  libdispatch.dylib                   0x03dde3ca _dispatch_queue_drain + 1065
    2015-09-18 23:51:05.356 Ross[24134:2660436] critical:   12  libdispatch.dylib                   0x03dddd15 _dispatch_queue_invoke + 563
    2015-09-18 23:51:05.356 Ross[24134:2660436] critical:   13  libdispatch.dylib                   0x03ddf7be _dispatch_root_queue_drain + 442
    2015-09-18 23:51:05.357 Ross[24134:2660436] critical:   14  libdispatch.dylib                   0x03ddf5fd _dispatch_worker_thread3 + 108
    2015-09-18 23:51:05.357 Ross[24134:2660436] critical:   15  libsystem_pthread.dylib             0x0412a1da _pthread_wqthread + 724
    2015-09-18 23:51:05.357 Ross[24134:2660436] critical:   16  libsystem_pthread.dylib             0x04127e2e start_wqthread + 30
    2015-09-18 23:51:05.358 Ross[24134:2660436] critical: 
    =================================================================
    Got a SIGSEGV while executing native code. This usually indicates
        a fatal error in the mono runtime or one of the native libraries 
        used by your application.
        =================================================================
    

    尽管如果我将Index()行更改为完全不添加任何项,但不会发生崩溃,执行流程将遇到“失败”控制台情况:

     CSSearchableIndex.DefaultSearchableIndex.Index (new CSSearchableItem[] { }, (error) => {
    

    我还尝试在 CSSearchableItemAttributeSet 对象,没有运气。

    你知道怎么飞行吗?

    1 回复  |  直到 10 年前
        1
  •  1
  •   Dmitry Kurilo    10 年前

    使用了错误的初始值设定项。而不是调用plain

    var attributes = new CSSearchableItemAttributeSet ();
    

    我必须指定itemContentType

    var attributes = new CSSearchableItemAttributeSet (itemContentType: "");
    

    https://developer.apple.com/library/prerelease/ios/documentation/CoreSpotlight/Reference/CSSearchableItemAttributeSet_Class/index.html#//apple_ref/occ/instm/CSSearchableItemAttributeSet/initWithItemContentType: