App Crash with exc_bad_access code Exception

柔情痞子 提交于 2019-12-11 07:40:38

问题


Let me introduce my functionality of App,I use push notification & addressbook and CoreTelephony Framework.

What I am doing in my application is , When i get Push notification, I save the number from the Payload in a Appdelegate Variable(Incoming_NO) , if there is no Such contact with this number , Ill create the new contact and save it. When i receive the Call , the same contact name appears as i added before , Later on I am allowing the user to Edit the Contact if he want to save the contact or to delete , When he edit the contact and later when i receive the Push notification with same number I am getting the exc_bad_access to (Incoming_NO) I have enabled the Zombie and i got the breakpoint error at the same place ..

Can anyone help me what is the issue .

    Received notification: {
        aps =     {
            alert = "Please help me-+918884718240";
            sound = "beep.caf";
        };
    }

Code :

 NSString* alertValue = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];

 NSRange range=[alertValue rangeOfString:@":"];
    NSString *param,*msg;
    NSRange range1=[alertValue rangeOfString:@":"];
    if (range1.location != NSNotFound)
    {
        param = [alertValue substringFromIndex:range1.location + range1.length];

        msg=[alertValue substringToIndex:range.location + range.length-1];
    }
    else
    {
        range1=[alertValue rangeOfString:@"-"];
        if (range1.location != NSNotFound)
        {
            param = [alertValue substringFromIndex:range1.location + range1.length];

            msg=[alertValue substringToIndex:range1.location + range1.length-1];
        }


    }
if(range.length!=0)
    {
        parts= [NSMutableArray arrayWithArray:[alertValue componentsSeparatedByString:@":"]];

    }else
    {
        parts = [NSMutableArray arrayWithArray:[alertValue componentsSeparatedByString:@"-"]];
    }

incoming_Number =[parts objectAtIndex:1];        

For this Variable(incoming_Number) I get the error when i receive the Push notification after saving the contact.

I tried to change incoming_Number type to NSString and NSMutableString , still the same error , I guess what happening is I am referring to the object which is released . But in debugger i can see it has the value .

来源:https://stackoverflow.com/questions/19396173/app-crash-with-exc-bad-access-code-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!