在Xcode 8升级后,iOS10中的应用程序崩溃,返回了malloc错误

在Xcode 8升级后,iOS10中的应用程序崩溃,返回了malloc错误,第1张

概述我最近升级到iOS10和 Xcode 8,之后一些以前正在运行的代码现在不再有效了.当代码运行时,应用程序崩溃并在控制台中显示以下错误消息: malloc:*对象0x1700bea80的错误:未分配被释放的指针 *在malloc_error_break中设置断点以进行调试 我已经做了一些测试,并将错误缩小到以下代码中的’createNativeAd’函数. 任何人都可以看到为什么会抛出这个错误? 我最近升级到iOS10和 Xcode 8,之后一些以前正在运行的代码现在不再有效了.当代码运行时,应用程序崩溃并在控制台中显示以下错误消息:

malloc:*对象0x1700bea80的错误:未分配被释放的指针
*在malloc_error_break中设置断点以进行调试

我已经做了一些测试,并将错误缩小到以下代码中的’createNativeAd’函数.

任何人都可以看到为什么会抛出这个错误?

////  FacebookAdplugin.m//  TestAdMobCombo////  Created by XIE liming on 14-11-8.////#import <FBAudIEnceNetwork/FBAudIEnceNetwork.h>#import "UITapGestureRecognizer+Spec.h"#import "FacebookAdplugin.h"#define TEST_BANNER_ID           @"726719434140206_777151452430337"#define TEST_INERSTITIAL_ID      @"726719434140206_777151589096990"#define TEST_NATIVE_ID           @"726719434140206_777151705763645"#define OPT_DEVICE_HASH          @"deviceHash"@interface FacebookAdplugin()<FBAdVIEwDelegate,FBInterstitialAdDelegate,FBNativeAdDelegate,UIGestureRecognizerDelegate>@property (assign) FBAdSize adSize;@property (nonatomic,retain) NSMutableDictionary* nativeads;- (voID) __removeNativeAd:(Nsstring*)adID;- (voID) fireNativeAdLoadEvent:(FBNativeAd*)nativeAd;@end// ------------------------------------------------------------------@interface UITrackingVIEw : UIVIEw@end@implementation UITrackingVIEw- (UIVIEw *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{    // Always ignore the touch event,so that we can scroll the webvIEw beneath.    // We will inovke GestureRecognizer callback ourselves.    return nil;}@end// ------------------------------------------------------------------@interface FlexNativeAd : NSObject@property (nonatomic,retain) Nsstring* adID;@property (nonatomic,retain) FBNativeAd* ad;@property (nonatomic,retain) UITrackingVIEw* vIEw;@property (assign) int x,y,w,h;- (FlexNativeAd*) init;@end@implementation FlexNativeAd- (FlexNativeAd*) init{    self.adID = NulL;    self.ad = NulL;    self.vIEw = NulL;    self.x = 0;    self.y = 0;    self.w = 0;    self.h = 0;    return self;}@end// ------------------------------------------------------------------@implementation FacebookAdplugin- (voID)pluginInitialize{    [super pluginInitialize];    self.adSize = [self __AdSizefromString:@"SMART_BANNER"];    self.nativeads = [[NSMutableDictionary alloc] init];}- (Nsstring*) __getProductShortname{    return @"FacebookAds";}- (Nsstring*) __getTestBannerID;{    return TEST_BANNER_ID;}- (Nsstring*) __getTestInterstitialID{    return TEST_INERSTITIAL_ID;}- (FBAdSize) __AdSizefromString:(Nsstring*)str{    FBAdSize sz;    if ([str isEqualToString:@"BANNER"]) {        sz = kFBAdSize320x50;    // other size not supported by facebook audIEnce network: FulL_BANNER,MEDIUM_RECTANGLE,leaderBOARD,SKYSCRAPER    //} else if ([str isEqualToString:@"SMART_BANNER"]) {    } else {        BOol isIPAD = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad);        sz = isIPAD ? kFBAdSizeHeight90Banner : kFBAdSizeHeight50Banner;    }    return sz;}- (voID) parSEOptions:(NSDictionary *)options{    [super parSEOptions:options];    Nsstring* str = [options objectForKey:OPT_AD_SIZE];    if(str) {        self.adSize = [self __AdSizefromString:str];    }    if(self.isTesting) {        self.testTraffic = true;        str = [options objectForKey:OPT_DEVICE_HASH];        if(str && [str length]>0) {            NSLog(@"set device hash: %@",str);            [FBAdSettings addTestDevice:str];        }        // Todo: add device hash,but kNow how to get the FB hash ID on ios ...    }}- (UIVIEw*) __createAdVIEw:(Nsstring*)adID{    FBAdVIEw* ad = [[FBAdVIEw alloc] initWithPlacementID:adID                                                  adSize:self.adSize                                      rootVIEwController:[self getVIEwController]];    ad.delegate= self;    if(self.adSize.size.height == 50 || self.adSize.size.height == 90) {        ad.autoresizingMask =        UIVIEwautoresizingFlexibleRightmargin |        UIVIEwautoresizingFlexibleleftmargin|        UIVIEwautoresizingFlexibleWIDth |        UIVIEwautoresizingFlexibletopmargin;    }    return ad;}- (int) __getAdVIEwWIDth:(UIVIEw*)vIEw{    return vIEw.frame.size.wIDth;}- (int) __getAdVIEwHeight:(UIVIEw*)vIEw{    return vIEw.frame.size.height;}- (voID) __loadAdVIEw:(UIVIEw*)vIEw{    if([vIEw isKindOfClass:[FBAdVIEw class]]) {        FBAdVIEw* ad = (FBAdVIEw*) vIEw;        [ad loadAd];    }}- (voID) __pauseAdVIEw:(UIVIEw*)vIEw{    if([vIEw isKindOfClass:[FBAdVIEw class]]) {        //FBAdVIEw* ad = (FBAdVIEw*) vIEw;        // [ad pause];    }}- (voID) __resumeAdVIEw:(UIVIEw*)vIEw{    if([vIEw isKindOfClass:[FBAdVIEw class]]) {        //FBAdVIEw* ad = (FBAdVIEw*) vIEw;        // [ad resume];    }}- (voID) __destroyAdVIEw:(UIVIEw*)vIEw{    if([vIEw isKindOfClass:[FBAdVIEw class]]) {        FBAdVIEw* ad = (FBAdVIEw*) vIEw;        ad.delegate = nil;    }}- (NSObject*) __createInterstitial:(Nsstring*)adID{    FBInterstitialAd* ad = [[FBInterstitialAd alloc] initWithPlacementID:adID];    ad.delegate = self;    return ad;}- (voID) __loadInterstitial:(NSObject*)interstitial{    if([interstitial isKindOfClass:[FBInterstitialAd class]]) {        FBInterstitialAd* ad = (FBInterstitialAd*) interstitial;        [ad loadAd];    }}- (voID) __showInterstitial:(NSObject*)interstitial{    if([interstitial isKindOfClass:[FBInterstitialAd class]]) {        FBInterstitialAd* ad = (FBInterstitialAd*) interstitial;        if(ad && ad.isAdValID) {            [ad showAdFromrootVIEwController:[self getVIEwController]];        }    }}- (voID) __destroyInterstitial:(NSObject*)interstitial{    if([interstitial isKindOfClass:[FBInterstitialAd class]]) {        FBInterstitialAd* ad = (FBInterstitialAd*) interstitial;        ad.delegate = nil;    }}- (voID)handleTapOnWebVIEw:(UITapGestureRecognizer *)sender{    //NSLog(@"handleTapOnWeb");    for(ID key in self.nativeads) {        FlexNativeAd* unit = (FlexNativeAd*) [self.nativeads objectForKey:key];        CGPoint point = [sender locationInVIEw:unit.vIEw];        if([unit.vIEw pointInsIDe:point withEvent:nil]) {            NSLog(@"Native Ad vIEw area tapped");            NSArray* handlers = [unit.vIEw gestureRecognizers];            for(ID handler in handlers) {                if([handler isKindOfClass:[UITapGestureRecognizer class]]) {                    UITapGestureRecognizer* tapHandler = (UITapGestureRecognizer*) handler;                    // Here we call the injected method,defined in "UITapGestureRecognizer+Spec.m"                    if([tapHandler respondsToSelector:@selector(performTapWithVIEw:andPoint:)]) {                        [tapHandler performTapWithVIEw:unit.vIEw andPoint:point];                    }                }            }        }    }}- (BOol)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer    shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{    return YES;}- (voID)createNativeAd:(CDVInvokedUrlCommand *)command{    NSLog(@"createNativeAd");    if([command.arguments count] >= 1) {        Nsstring* adID = [command argumentAtIndex:0];        if(self.testTraffic) adID = TEST_INERSTITIAL_ID;        FlexNativeAd* unit = [self.nativeads objectForKey:adID];        if(unit) {            if(unit.adID) {                [self __removeNativeAd:unit.adID];            }        }        unit = [[FlexNativeAd alloc] init];        unit.adID = adID;        CGRect adRect = {{0,0},{0,0}};        unit.vIEw = [[UITrackingVIEw alloc] initWithFrame:adRect];        [[self getVIEw] addSubvIEw:unit.vIEw];        // add tap handler to handle tap on webvIEw        UITapGestureRecognizer *webVIEwTapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapOnWebVIEw:)];        webVIEwTapped.numberOfTapsrequired = 1;        webVIEwTapped.delegate = self;        [[self getVIEw] addGestureRecognizer:webVIEwTapped];        if(self.isTesting) {            [unit.vIEw setBackgroundcolor:[[UIcolor greencolor] colorWithAlphaComponent:0.2f]];        }        unit.ad = [[FBNativeAd alloc] initWithPlacementID:adID];        unit.ad.delegate = self;        [self.nativeads setobject:unit forKey:adID];        [unit.ad loadAd];        [self sendpluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] to:command.callbackID];    } else {        [self sendpluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsstring:@"invalID arguments"] to:command.callbackID];    }}- (voID) __removeNativeAd:(Nsstring*)adID{    FlexNativeAd* unit = [self.nativeads objectForKey:adID];    if(unit) {        [self.nativeads removeObjectForKey:adID];        if(unit.vIEw) {            CGRect adFrame = {{0,0}};            unit.vIEw.frame = adFrame;            [unit.vIEw removeFromSupervIEw];        }        if(unit.ad) {            [unit.ad unregisterVIEw];        }    }}- (voID)removeNativeAd:(CDVInvokedUrlCommand *)command{    NSLog(@"removeNativeAd");    if([command.arguments count] >= 1) {        Nsstring* adID = [command argumentAtIndex:0];        [self __removeNativeAd:adID];        [self sendpluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] to:command.callbackID];    } else {        [self sendpluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsstring:@"invalID arguments"] to:command.callbackID];    }}- (voID)setNativeAdClickArea:(CDVInvokedUrlCommand *)command{    NSLog(@"setNativeAdClickArea");    if([command.arguments count] >= 5) {        Nsstring* adID = [command argumentAtIndex:0];        FlexNativeAd* unit = [self.nativeads objectForKey:adID];        if(unit && unit.vIEw) {            int x = [[command argumentAtIndex:1 withDefault:@"0"] intValue];            int y = [[command argumentAtIndex:2 withDefault:@"0"] intValue];            int w = [[command argumentAtIndex:3 withDefault:@"0"] intValue];            int h = [[command argumentAtIndex:4 withDefault:@"0"] intValue];            CGRect adRect = {{x,y},{w,h}};            unit.vIEw.frame = adRect;            [self sendpluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] to:command.callbackID];        } else {            [self sendpluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsstring:@"native ad not exists"] to:command.callbackID];        }    } else {        [self sendpluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsstring:@"invalID arguments"] to:command.callbackID];    }}#pragma mark FBAdVIEwDelegate implementation/** * document.addEventListener('onAdLoaded',function(data)); * document.addEventListener('onAdFailLoad',function(data)); * document.addEventListener('onAdPresent',function(data)); * document.addEventListener('onAddismiss',function(data)); * document.addEventListener('onAdLeaveApp',function(data)); */- (voID)adVIEwDIDClick:(FBAdVIEw *)adVIEw{    [self fireAdEvent:EVENT_AD_LEAVEAPP withType:ADTYPE_BANNER];}- (voID)adVIEwDIDFinishHandlingClick:(FBAdVIEw *)adVIEw{    [self fireAdEvent:EVENT_AD_disMISS withType:ADTYPE_BANNER];}- (voID)adVIEwDIDLoad:(FBAdVIEw *)adVIEw{    if((! self.bannerVisible) && self.autoShowBanner) {        dispatch_async(dispatch_get_main_queue(),^{            [self __showBanner:self.adposition atX:self.posX atY:self.posY];        });    }    [self fireEvent:[self __getProductShortname] event:@"onBannerReceive" withData:NulL];    [self fireAdEvent:EVENT_AD_LOADED withType:ADTYPE_BANNER];}- (voID)adVIEw:(FBAdVIEw *)adVIEw dIDFailWithError:(NSError *)error{    [self fireAdErrorEvent:EVENT_AD_FAILLOAD withCode:(int)error.code withMsg:[error localizedDescription] withType:ADTYPE_BANNER];}- (voID)adVIEwWillLogImpression:(FBAdVIEw *)adVIEw{    [self fireAdEvent:EVENT_AD_PRESENT withType:ADTYPE_BANNER];}///////////////////////////////////////////////////////////////////////////////////////////////////#pragma mark - FBInterstitialAdDelegate/** * document.addEventListener('onAdLoaded',function(data)); */- (voID)interstitialAdDIDLoad:(FBInterstitialAd *)interstitialAd{    if (self.interstitial && self.autoShowInterstitial) {        dispatch_async(dispatch_get_main_queue(),^{            [self __showInterstitial:self.interstitial];        });    }    [self fireAdEvent:EVENT_AD_LOADED withType:ADTYPE_INTERSTITIAL];}- (voID)interstitialAd:(FBInterstitialAd *)interstitialAd dIDFailWithError:(NSError *)error{    [self fireAdErrorEvent:EVENT_AD_FAILLOAD withCode:(int)error.code withMsg:[error localizedDescription] withType:ADTYPE_INTERSTITIAL];}- (voID)interstitialAdDIDClick:(FBInterstitialAd *)interstitialAd{    [self fireAdEvent:EVENT_AD_LEAVEAPP withType:ADTYPE_INTERSTITIAL];}- (voID)interstitialAdDIDClose:(FBInterstitialAd *)interstitialAd{    [self fireAdEvent:EVENT_AD_disMISS withType:ADTYPE_INTERSTITIAL];    if(self.interstitial) {        [self __destroyInterstitial:self.interstitial];        self.interstitial = nil;    }}- (voID)interstitialADWillClose:(FBInterstitialAd *)interstitialAd{    [self fireAdEvent:EVENT_AD_WILLdisMISS withType:ADTYPE_INTERSTITIAL];}- (voID)interstitialADWillLogImpression:(FBInterstitialAd *)interstitialAd{    [self fireAdEvent:EVENT_AD_WILLPRESENT withType:ADTYPE_INTERSTITIAL];}/** * document.addEventListener('onAdLoaded',function(data)); */- (voID)nativeAd:(FBNativeAd *)nativeAd dIDFailWithError:(NSError *)error{    [self fireAdErrorEvent:EVENT_AD_FAILLOAD withCode:(int)error.code withMsg:[error localizedDescription] withType:ADTYPE_NATIVE];}- (voID)nativeAdDIDClick:(FBNativeAd *)nativeAd{    [self fireAdEvent:EVENT_AD_LEAVEAPP withType:ADTYPE_NATIVE];}- (voID)nativeAdDIDFinishHandlingClick:(FBNativeAd *)nativeAd{    [self fireAdEvent:EVENT_AD_disMISS withType:ADTYPE_NATIVE];}- (voID)nativeAdDIDLoad:(FBNativeAd *)nativeAd{    [self fireNativeAdLoadEvent:nativeAd];}- (voID) fireNativeAdLoadEvent:(FBNativeAd*)nativeAd{    [self.nativeads enumerateKeysAndobjectsUsingBlock:^(ID key,ID obj,BOol *stop) {        Nsstring* adID = (Nsstring*) key;        FlexNativeAd* unit = (FlexNativeAd*) obj;        if(unit && unit.ad == nativeAd) {            Nsstring *TitleForAd = nativeAd.Title;            Nsstring *bodyTextForAd = nativeAd.body;            FBAdImage *coverImage = nativeAd.coverImage;            FBAdImage *iconForAd = nativeAd.icon;            Nsstring *socialContextForAd = nativeAd.socialContext;            struct FBAdStarrating appratingForAd = nativeAd.starrating;            Nsstring *TitleForAdbutton = nativeAd.callToAction;            NSMutableDictionary* coverInfo = [[NSMutableDictionary alloc] init];            [coverInfo setValue:[coverImage.url absoluteString] forKey:@"url"];            [coverInfo setValue:[NSNumber numberWithInt:coverImage.wIDth] forKey:@"wIDth"];            [coverInfo setValue:[NSNumber numberWithInt:coverImage.height] forKey:@"height"];            NSMutableDictionary* iconInfo = [[NSMutableDictionary alloc] init];            [iconInfo setValue:[iconForAd.url absoluteString] forKey:@"url"];            [iconInfo setValue:[NSNumber numberWithInt:iconForAd.wIDth] forKey:@"wIDth"];            [iconInfo setValue:[NSNumber numberWithInt:iconForAd.height] forKey:@"height"];            NSMutableDictionary* adRes = [[NSMutableDictionary alloc] init];            [adRes setValue:coverInfo forKey:@"coverImage"];            [adRes setValue:iconInfo forKey:@"icon"];            [adRes setValue:TitleForAd forKey:@"Title"];            [adRes setValue:bodyTextForAd forKey:@"body"];            [adRes setValue:socialContextForAd forKey:@"socialContext"];            [adRes setValue:[NSNumber numberWithfloat:appratingForAd.value] forKey:@"rating"];            [adRes setValue:[NSNumber numberWithInt:appratingForAd.scale] forKey:@"ratingScale"];            [adRes setValue:TitleForAdbutton forKey:@"buttonText"];            NSMutableDictionary* Json = [[NSMutableDictionary alloc] init];            [Json setValue:[self __getProductShortname] forKey:@"adNetwork"];            [Json setValue:EVENT_AD_LOADED forKey:@"adEvent"];            [Json setValue:ADTYPE_NATIVE forKey:@"adType"];            [Json setValue:adID forKey:@"adID"];            [Json setValue:adRes forKey:@"adRes"];            NSError * err;            NSData * JsonData = [NSJsONSerialization dataWithJsONObject:Json options:0 error:&err];            Nsstring * JsonStr = [[Nsstring alloc] initWithData:JsonData enCoding:NSUTF8StringEnCoding];            [unit.ad registerVIEwForInteraction:unit.vIEw withVIEwController:[self getVIEwController]];            [self fireEvent:[self __getProductShortname] event:EVENT_AD_LOADED withData:JsonStr];            *stop = YES;        }    }];}- (voID)nativeADWillLogImpression:(FBNativeAd *)nativeAd{    [self fireAdEvent:EVENT_AD_PRESENT withType:ADTYPE_NATIVE];}@end

完整的源代码可以在https://github.com/floatinghotpot/cordova-plugin-facebookads找到

解决方法 阅读此答案 https://stackoverflow.com/a/40068196/935070

Mac的Safari的自动网络检查器正在崩溃横幅

只是禁用自动Web检查

Safari>开发>设备>自动显示jscontext的Web检查器

总结

以上是内存溢出为你收集整理的在Xcode 8升级后,iOS10中的应用程序崩溃,返回了malloc错误全部内容,希望文章能够帮你解决在Xcode 8升级后,iOS10中的应用程序崩溃,返回了malloc错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1001764.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存