Swift:使用NSExeption的未捕获例外终止应用程序?

时间:2016-11-24 21:41:13

标签: swift xcode

在你说&#34之前,这是一个问题的重复",没有。我之前已经检查了这个问题,它告诉我的是检查我的网点。我的所有商店都是正确的,我不知道为什么我会收到这个错误。这是错误的详细信息:

*** Terminating app due to uncaught exception     'NSInvalidArgumentException', reason: '-[NSTaggedPointerString objectForKeyedSubscript:]: unrecognized selector sent to instance 0xa00000000006e652'
*** First throw call stack:
(
0   CoreFoundation                      0x000000010ddf5d4b __exceptionPreprocess + 171
1   libobjc.A.dylib                     0x000000010d85e21e objc_exception_throw + 48
2   CoreFoundation                      0x000000010de65f04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3   CoreFoundation                      0x000000010dd7b005 ___forwarding___ + 1013
4   CoreFoundation                      0x000000010dd7ab88 _CF_forwarding_prep_0 + 120
5   Calc                                0x0000000108d00b37 -[MPCoreInstanceProvider appTransportSecuritySettings] + 284
6   Calc                                0x0000000108cc4147 +[MPAdServerURLBuilder queryParameterForAppTransportSecurity] + 76
7   Calc                                0x0000000108cc30d4 +[MPAdServerURLBuilder URLWithAdUnitID:keywords:location:versionParameterName:version:testing:desiredAssets:adSequence:] + 1674
8   Calc                                0x0000000108cc2a01 +[MPAdServerURLBuilder URLWithAdUnitID:keywords:location:versionParameterName:version:testing:desiredAssets:] + 173
9   Calc                                0x0000000108cc2920 +[MPAdServerURLBuilder URLWithAdUnitID:keywords:location:testing:] + 116
10  Calc                                0x0000000108cd3cde -[MPBannerAdManager loadAdWithURL:] + 470
11  Calc                                0x0000000108cc03a2 -[MPAdView loadAd] + 48
12  Calc                                0x000000010895aa1f _TFFC4Calc18MenuViewController11viewDidLoadFT_T_L_7loadAdsfT_T_ + 175
13  Calc                                0x0000000108957d18 _TFC4Calc18MenuViewController11viewDidLoadfT_T_ + 8104
14  Calc                                0x000000010895b632 _TToFC4Calc18MenuViewController11viewDidLoadfT_T_ + 34
15  UIKit                               0x00000001099cb8b1 -[UIViewController loadViewIfRequired] + 1258
16  UIKit                               0x00000001099cbce4 -[UIViewController view] + 27
17  UIKit                               0x0000000109895405 -[UIWindow addRootViewControllerViewIfPossible] + 71
18  UIKit                               0x0000000109895b56 -[UIWindow _setHidden:forced:] + 293
19  UIKit                               0x00000001098a9469 -[UIWindow makeKeyAndVisible] + 42
20  Calc                                0x0000000108c32264 _TFC4Calc11AppDelegate11applicationfTCSo13UIApplication29didFinishLaunchingWithOptionsGSqGVs10DictionaryVSC29UIApplicationLaunchOptionsKeyP____Sb + 5716
21  Calc                                0x0000000108c34674 _TToFC4Calc11AppDelegate11applicationfTCSo13UIApplication29didFinishLaunchingWithOptionsGSqGVs10DictionaryVSC29UIApplicationLaunchOptionsKeyP____Sb + 180
22  UIKit                               0x0000000109820312 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 290
23  UIKit                               0x0000000109821c97 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4236
24  UIKit                               0x000000010982803d -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731
25  UIKit                               0x00000001098251bd -[UIApplication workspaceDidEndTransaction:] + 188
26  FrontBoardServices                  0x00000001160176cb __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
27  FrontBoardServices                  0x0000000116017544 -[FBSSerialQueue _performNext] + 189
28  FrontBoardServices                  0x00000001160178cd -[FBSSerialQueue _performNextFromRunLoopSource] + 45
29  CoreFoundation                      0x000000010dd9a761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
30  CoreFoundation                      0x000000010dd7f98c __CFRunLoopDoSources0 + 556
31  CoreFoundation                      0x000000010dd7ee76 __CFRunLoopRun + 918
32  CoreFoundation                      0x000000010dd7e884 CFRunLoopRunSpecific + 420
33  UIKit                               0x0000000109823a3a -[UIApplication _run] + 434
34  UIKit                               0x0000000109829bb8 UIApplicationMain + 159
35  Calc                                0x0000000108c4617f main + 111
36  libdyld.dylib                       0x0000000110df668d start + 1
37  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

1 个答案:

答案 0 :(得分:2)

您的应用的Info.plist似乎可能没有NSAppTransportSecurity或其中一个孩子的正确值。

退房:MPCoreInstanceProvider.m

“这是一个问题的重复” - 下次查看您的堆栈跟踪,它包含所需的所有提示:

  • 靠近顶部你有-[NSObject(NSObject) doesNotRecognizeSelector:]抛出异常(objc_exception_throw ...)
    • doesNotRecognizeSelector表示某些代码尝试调用不可用的方法
    • 哪一个?再看上面的内容:-[NSTaggedPointerString objectForKeyedSubscript:]
    • 所以缺少的方法是objectForKeyedSubscript:,这就是Objective-C编译器为表达式生成的内容:myObject[@"title"]
    • 它还告诉你调用该方法的对象的类:NSTaggedPointerString,所以有些代码尝试在普通字符串上使用[],这没有多大意义
  • 接下来要检查的是谁调用了该代码:-[MPCoreInstanceProvider appTransportSecuritySettings]是堆栈中的最后一个常规代码
    • 所以你要DuckDuckGo MPCoreInstanceProvider并找到MPCoreInstanceProvider.m
    • 碰巧有appTransportSecuritySettings方法
    • 查看它抓取字典NSDictionary *atsSettingsDictionary = [NSBundle mainBundle].infoDictionary[kMoPubAppTransportSecurityDictionaryKey];
    • 的代码
    • 然后对该字典及其值进行了大量[]操作
  • 结论:[]中有一个在期待字典时遇到字符串。