我在应用程序中添加了admob
。
如果没有互联网连接,应用程序将崩溃并出现以下错误。
Phrasebook(2806,0x3196a28) malloc: *** error for object 0xc0e27a0:
incorrect checksum for freed object - object was probably modified after being freed.
set a breakpoint in malloc_error_break to debug
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
GADBannerView *bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
bannerView_.adUnitID = MyAdUnitID;
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self;
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];
return bannerView_;
}
-(float)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
// admob ad size height
return 50.0;
}
我确实在break point
中设置了malloc_error_break
,这就是回溯
* thread #1: tid = 0x245a6, 0x03101875 libsystem_c.dylib`malloc_error_break, queue = 'com.apple.main-thread, stop reason = breakpoint 1.1
frame #0: 0x03101875 libsystem_c.dylib`malloc_error_break
frame #1: 0x0310a17a libsystem_c.dylib`szone_error + 270
frame #2: 0x0310b482 libsystem_c.dylib`free_list_checksum_botch + 50
frame #3: 0x0310b5ad libsystem_c.dylib`tiny_free_list_remove_ptr + 185
frame #4: 0x03105171 libsystem_c.dylib`szone_free + 1601
frame #5: 0x023622e8 CoreFoundation`__CFAllocatorSystemDeallocate + 24
frame #6: 0x023622b4 CoreFoundation`CFAllocatorDeallocate + 100
frame #7: 0x0236200e CoreFoundation`CFRelease + 1134
frame #8: 0x0000ebd0 Phrasebook`-[GADTiming dealloc] + 66
frame #9: 0x02174692 libobjc.A.dylib`objc_object::sidetable_release(bool) + 268
frame #10: 0x02175adf libobjc.A.dylib`-[NSObject release] + 25
frame #11: 0x000303af Phrasebook`-[GADAdFetcher dealloc] + 114
frame #12: 0x02174692 libobjc.A.dylib`objc_object::sidetable_release(bool) + 268
frame #13: 0x02173e81 libobjc.A.dylib`objc_release + 49
frame #14: 0x02160b44 libobjc.A.dylib`objc_setProperty_non_gc(objc_object*, objc_selector*, int, objc_object*, signed char, signed char) + 173
frame #15: 0x02160d3a libobjc.A.dylib`objc_setProperty + 47
frame #16: 0x00024614 Phrasebook`-[GADSlot setAdFetcher:] + 63
frame #17: 0x000216dd Phrasebook`-[GADSlot loadAdHTMLFromURL:usingActivationOverlayURL:] + 466
frame #18: 0x00022796 Phrasebook`-[GADSlot loadAdURL:] + 733
frame #19: 0x0003ff4b Phrasebook`-[GADJavaScriptController loadAdURL:] + 217
frame #20: 0x01e36bf9 Foundation`__57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke + 40
frame #21: 0x0243c524 CoreFoundation`__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
frame #22: 0x0239400b CoreFoundation`_CFXNotificationPost + 2859
frame #23: 0x01d70951 Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 98
frame #24: 0x0001c9d3 Phrasebook`-[GADNotificationCenter postNotificationFromURL:object:] + 126
frame #25: 0x0001ca42 Phrasebook`-[GADNotificationCenter delayedPosting:] + 103
frame #26: 0x01d9a12c Foundation`__NSFireDelayedPerform + 372
frame #27: 0x0239ebd6 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
frame #28: 0x0239e5bd CoreFoundation`__CFRunLoopDoTimer + 1181
frame #29: 0x02386628 CoreFoundation`__CFRunLoopRun + 1816
frame #30: 0x02385ac3 CoreFoundation`CFRunLoopRunSpecific + 467
frame #31: 0x023858db CoreFoundation`CFRunLoopRunInMode + 123
frame #32: 0x038209e2 GraphicsServices`GSEventRunModal + 192
frame #33: 0x03820809 GraphicsServices`GSEventRun + 104
frame #34: 0x00ed1d3b UIKit`UIApplicationMain + 1225
frame #35: 0x000056bd Phrasebook`main(argc=1, argv=0xbfffedf8) + 141 at main.m:16
frame #36: 0x03062725 libdyld.dylib`start + 1
这个问题的最佳解决方案是什么,我想在使用本地GADBannerView之前检查是否有互联网连接
进一步测试我收到了这个回溯
(lldb) bt
* thread #4: tid = 0x455eb, 0x021730b2 libobjc.A.dylib`objc_msgSend + 14, name = 'WebThread, stop reason = EXC_BAD_ACCESS (code=2, address=0xc)
frame #0: 0x021730b2 libobjc.A.dylib`objc_msgSend + 14
frame #1: 0x05de1975 WebKit`WebFrameLoaderClient::cancelPolicyCheck() + 37
frame #2: 0x06a2927e WebCore`WebCore::PolicyChecker::stopCheck() + 30
frame #3: 0x062f6f1f WebCore`WebCore::FrameLoader::loadWithDocumentLoader(WebCore::DocumentLoader*, WebCore::FrameLoadType, WTF::PassRefPtr<WebCore::FormState>) + 495
frame #4: 0x062f610d WebCore`WebCore::FrameLoader::loadWithNavigationAction(WebCore::ResourceRequest const&, WebCore::NavigationAction const&, bool, WebCore::FrameLoadType, WTF::PassRefPtr<WebCore::FormState>) + 573
frame #5: 0x062f3c61 WebCore`WebCore::FrameLoader::loadURL(WebCore::KURL const&, WTF::String const&, WTF::String const&, bool, WebCore::FrameLoadType, WTF::PassRefPtr<WebCore::Event>, WTF::PassRefPtr<WebCore::FormState>) + 1297
frame #6: 0x062ef1c2 WebCore`WebCore::FrameLoader::loadFrameRequest(WebCore::FrameLoadRequest const&, bool, bool, WTF::PassRefPtr<WebCore::Event>, WTF::PassRefPtr<WebCore::FormState>, WebCore::ShouldSendReferrer) + 722
frame #7: 0x062ee980 WebCore`WebCore::FrameLoader::urlSelected(WebCore::FrameLoadRequest const&, WTF::PassRefPtr<WebCore::Event>, bool, bool, WebCore::ShouldSendReferrer, WebCore::ShouldReplaceDocumentIfJavaScriptURL) + 336
frame #8: 0x062ee6a2 WebCore`WebCore::FrameLoader::changeLocation(WebCore::SecurityOrigin*, WebCore::KURL const&, WTF::String const&, bool, bool, bool) + 178
frame #9: 0x069e2d8a WebCore`WebCore::ScheduledURLNavigation::fire(WebCore::Frame*) + 122
frame #10: 0x069e1913 WebCore`WebCore::NavigationScheduler::timerFired(WebCore::Timer<WebCore::NavigationScheduler>*) + 99
frame #11: 0x069e2717 WebCore`WebCore::Timer<WebCore::NavigationScheduler>::fired() + 39
frame #12: 0x06deed40 WebCore`WebCore::ThreadTimers::sharedTimerFiredInternal() + 192
frame #13: 0x06deebd6 WebCore`WebCore::ThreadTimers::sharedTimerFired() + 22
frame #14: 0x06c3f37b WebCore`WebCore::timerFired(__CFRunLoopTimer*, void*) + 27
frame #15: 0x0239ebd6 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
frame #16: 0x0239e5bd CoreFoundation`__CFRunLoopDoTimer + 1181
frame #17: 0x02386628 CoreFoundation`__CFRunLoopRun + 1816
frame #18: 0x02385ac3 CoreFoundation`CFRunLoopRunSpecific + 467
frame #19: 0x023858db CoreFoundation`CFRunLoopRunInMode + 123
frame #20: 0x06e50f00 WebCore`RunWebThread(void*) + 608
frame #21: 0x030e85b7 libsystem_c.dylib`_pthread_start + 344
答案 0 :(得分:0)
我最终检查了互联网连接,取自answer。
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
// bing.com load faster than google.com
NSURL *scriptUrl = [NSURL URLWithString:@"http://www.bing.com"];
NSData *data = [NSData dataWithContentsOfURL:scriptUrl];
if (data){
// Device is connected to the internet
GADBannerView *bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
bannerView_.adUnitID = MyAdUnitID;
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self;
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];
return bannerView_;
}else{
// Device is not connected to the internet
UIView *emptyView = [[UIView alloc] init];
return emptyView;
}
}
答案 1 :(得分:0)
更新:我的崩溃已通过刚刚发布的适用于iOS的Google移动广告SDK 6.8.0修复。
我也在谷歌移动广告SDK 6.7.0 for iOS中看到这一点。
似乎有效的解决方法在你的
中(void)adView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(GADRequestError *)错误;
从superview中删除bannerAdView,分配并设置一个新的。(/ p>)
有关详细信息,请参阅https://groups.google.com/forum/#!searchin/google-admob-ads-sdk/crash $ 20airplane / google-admob-ads-sdk / tSgHL7X0aWU / jNvm5_SO6iwJ