尝试在具有多个不同视图控制器的通用应用程序中实现iAd,尝试实现Apple的iAd套件中的示例代码,既是单个视图控制器中的基本代码,也是单独使用导航控制器代码,都会导致崩溃是指在nil时添加到字典中的pngData。视图控制器中没有字典,也没有任何名为pngData的字典。 这是堆栈跟踪 -
2012-03-14 15:24:24.389 TheApp[11372:207] CRASH: -[__NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: pngData)
2012-03-14 15:24:24.390 TheApp[11372:207] Stack Trace: (
0 CoreFoundation 0x0328f5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x030be313 objc_exception_throw + 44
2 CoreFoundation 0x03247ef8 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x03247e6a +[NSException raise:format:] + 58
4 CoreFoundation 0x0328de15 -[__NSCFDictionary setObject:forKey:] + 293
5 iAd 0x001a0cd8 -[ADBannerController executeBannerViewActionFrom:withClickLocation:] + 422
6 iAd 0x001914d8 -[ADBannerView touchesEnded:withEvent:] + 355
7 UIKit 0x00497ded -[UIWindow _sendTouchesForEvent:] + 567
8 UIKit 0x00478c37 -[UIApplication sendEvent:] + 447
9 UIKit 0x0047df2e _UIApplicationHandleEvent + 7576
10 GraphicsServices 0x03828992 PurpleEventCallback + 1550
11 CoreFoundation 0x03270944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
12 CoreFoundation 0x031d0cf7 __CFRunLoopDoSource1 + 215
13 CoreFoundation 0x031cdf83 __CFRunLoopRun + 979
14 CoreFoundation 0x031cd840 CFRunLoopRunSpecific + 208
15 CoreFoundation 0x031cd761 CFRunLoopRunInMode + 97
16 GraphicsServices 0x038271c4 GSEventRunModal + 217
17 GraphicsServices 0x03827289 GSEventRun + 115
18 UIKit 0x00481c93 UIApplicationMain + 1160
19 TheApp 0x00002039 main + 169
20 TheApp 0x00001f85 start + 53
21 ??? 0x00000001 0x0 + 1
)
就在崩溃之前,当我点击横幅时出现了一堆错误,超过50个与CGContext有关并且都非常类似于此
<Error>:CGContextRestoreGState: invalid context 0x0
<Error>: CGContextSetBaseCTM: invalid context 0x0
<Error>: CGContextRestoreGState: invalid context 0x0
<Error>: CGContextRestoreGState: invalid context 0x0
<Error>: CGContextSetBaseCTM: invalid context 0x0
我把所有例外的断点都放在 -
int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([TheAppAppDelegate class]));
我搜索了高低,找不到这个答案,最后一件事,它在iOS 5.0模拟器中工作正常但在iOS4.3模拟器中崩溃