Ios 应用程序崩溃,exc\u访问代码错误
让我介绍一下我的应用程序功能,我使用推送通知和地址簿以及Ios 应用程序崩溃,exc\u访问代码错误,ios,exception-handling,exc-bad-access,appdelegate,Ios,Exception Handling,Exc Bad Access,Appdelegate,让我介绍一下我的应用程序功能,我使用推送通知和地址簿以及corethony框架 我在应用程序中所做的是,当我收到推送通知时,我将有效负载中的号码保存在Appdelegate变量(传入的\u NO)中,如果没有与此号码相关的联系人,我将创建新联系人并保存它。 当我接到电话时,会显示与我之前添加的联系人姓名相同的联系人姓名,稍后我会允许用户编辑联系人,如果他想保存联系人或删除,当他编辑联系人时,以及稍后当我收到具有相同号码的推送通知时,我将获得exc\u bad\u访问权限(传入\u否)我已经启用了
corethony
框架
我在应用程序中所做的是,当我收到推送通知时,我将有效负载中的号码保存在Appdelegate变量(传入的\u NO)中,如果没有与此号码相关的联系人,我将创建新联系人并保存它。
当我接到电话时,会显示与我之前添加的联系人姓名相同的联系人姓名,稍后我会允许用户编辑联系人,如果他想保存联系人或删除,当他编辑联系人时,以及稍后当我收到具有相同号码的推送通知时,我将获得exc\u bad\u访问权限(传入\u否)我已经启用了僵尸,我在同一个地方得到了断点错误
有人能帮我解决什么问题吗
Received notification: {
aps = {
alert = "Please help me-+918884718240";
sound = "beep.caf";
};
}
代码:
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];
对于这个变量(传入的_编号),我在保存联系人后收到推送通知时会收到错误
我试图将传入的\u Number类型更改为NSString和NSMutableString,仍然是相同的错误,我猜发生的是我指的是发布的对象。但在调试器中,我可以看到它具有值
添加联系人代码:
- (void)setContacts:(UIImage *) imgdata :(NSString *)incoming_number {
ABRecordRef person=NULL;
ABRecordRef loopingPerson=NULL;
_Bool vizzical_present=false;
CFErrorRef myError = NULL;
NSArray *allContacts;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &myError);
// ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(nil, nil);
__block BOOL accessGranted = NO;
if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
accessGranted = granted;
dispatch_semaphore_signal(sema);
});
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
//dispatch_release(sema);
}
else { // we're on iOS 5 or older
accessGranted = YES;
}
if (accessGranted) {
// int count = (int) ABAddressBookGetPersonCount(addressBook);
allContacts = (__bridge_transfer NSArray
*)ABAddressBookCopyArrayOfAllPeople(addressBook);
for(CFIndex i = 1; i < allContacts.count; i++)
{
loopingPerson = (__bridge ABRecordRef)allContacts[i];
CFStringRef firstName;
// char *lastNameString, *firstNameString;
firstName = ABRecordCopyValue(loopingPerson, kABPersonFirstNameProperty);
if([(__bridge NSString *)(firstName) isEqualToString:@"VizziCal"]){
vizzical_present=true;
}
ABMutableMultiValueRef phoneNumbers = ABRecordCopyValue(loopingPerson, kABPersonPhoneProperty);
// NSMutableArray *numbersArray = [[NSMutableArray alloc] init];
// CFStringRef phoneNumberLabel = ABMultiValueCopyLabelAtIndex( phoneNumbers, 0 );
CFStringRef phoneNumberValue = ABMultiValueCopyValueAtIndex( phoneNumbers, 0 );
NSString* noSpaces =
[[(__bridge NSString *)phoneNumberValue componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]componentsJoinedByString:@""];
if(phoneNumberValue!=NULL){
NSString* noHypen =
[noSpaces stringByReplacingOccurrencesOfString:@"-" withString:@""];
// CFStringRef phoneNumberLocalizedLabel = ABAddressBookCopyLocalizedLabel( phoneNumberLabel );
// NSString *addPlus=[[NSString alloc]initWithFormat:@"%@",incoming_number] ;
if([incoming_number isEqual:noHypen] || ([incoming_number rangeOfString:noHypen].location!=NSNotFound)){
NSLog(@"%@ and %@ and %ld",incoming_number,noHypen,i);
person=loopingPerson;
break;
}
}
}
if(person!=NULL){
CFErrorRef error = nil;
CFDataRef imageData = ABPersonCopyImageData(person);
NSData* imageData1 = (__bridge NSData*)ABPersonCopyImageData(person);
UIImage *image = [UIImage imageWithData:(__bridge NSData *)(imageData)];
UIImage *image1 = [UIImage imageWithData:(NSData *)(imageData1)];
NSData *dataRef;
UIImage *mergedImage;
if(image!=NULL)
{
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
savedImagePath= [self saveImage:image1 forPerson:@"image"];
});
dataRef = UIImagePNGRepresentation(imgdata);
CFRelease(imageData);
}
else{
if(imgdata.size.height <480 && imgdata.size.width<320)
{
UIImage *image = [UIImage imageNamed:@"blank_image.png"];
mergedImage=[self mergeTwoImages:imgdata :image];
CGFloat width = imgdata.size.width;
CGFloat height = imgdata.size.height;
NSLog(@"Height:%f and Width =%f",width,height);
dataRef = UIImagePNGRepresentation(mergedImage);
}
else{
dataRef = UIImagePNGRepresentation(imgdata);
}
}
CFDataRef cfDataRef = CFDataCreate(NULL, [dataRef bytes], [dataRef length]);
if (ABPersonHasImageData(person)) {
ABPersonRemoveImageData(person, &error);
ABAddressBookSave(addressBook, &error);
}
//ABRecordSetValue(person, kABPersonFirstNameProperty, @"Don Juan", NULL);
// ABAddressBookAddRecord(addressBook, person, &error);
if (ABPersonSetImageData(person, cfDataRef, &error)) {
if (ABAddressBookHasUnsavedChanges(addressBook)) {
NSLog(@"has unsaved changes");
} else {
NSLog(@"nothing to save");
}
if (ABAddressBookSave(addressBook, &error)) {
NSLog(@"saved");
} else {
NSLog(@"not saved");
}
}
}
else{
if(!vizzical_present)
{
ABRecordRef newPerson = ABPersonCreate();
ABRecordSetValue(newPerson, kABPersonFirstNameProperty, @"VizziCal", &myError);
CFDataRef dataRef = (__bridge CFDataRef)(UIImagePNGRepresentation(imgdata));
[prefs setBool:YES forKey:@"contact-created"];
//Phone number is a list of phone number, so create a multivalue
ABMutableMultiValueRef phoneNumberMultiValue =
ABMultiValueCreateMutable(kABPersonPhoneProperty);
ABMultiValueAddValueAndLabel(phoneNumberMultiValue ,(__bridge CFTypeRef)(incoming_number),kABPersonPhoneMobileLabel, NULL);
// ...
// Set other properties
ABRecordSetValue(newPerson, kABPersonPhoneProperty, phoneNumberMultiValue, &myError);
// ...
ABAddressBookAddRecord(addressBook, newPerson, &myError);
ABAddressBookSave(addressBook, &myError);
if (myError != NULL)
{
CFStringRef errorDesc = CFErrorCopyDescription(myError);
NSLog(@"Contact not saved: %@", errorDesc);
CFRelease(errorDesc);
}
if (ABPersonSetImageData(newPerson, dataRef, &myError)) {
if (ABAddressBookHasUnsavedChanges(addressBook)) {
NSLog(@"has unsaved changes");
} else {
NSLog(@"nothing to save");
}
if (ABAddressBookSave(addressBook, &myError)) {
NSLog(@"saved");
} else {
NSLog(@"not saved");
}
}
CFRelease(newPerson);
CFRelease(addressBook);
CFRelease(phoneNumberMultiValue);
}
else
{
ABRecordRef newPerson = ABPersonCreate();
for(CFIndex i = 1; i < allContacts.count; i++)
{
loopingPerson = (__bridge ABRecordRef)allContacts[i];
CFStringRef firstName;
// char *lastNameString, *firstNameString;
firstName = ABRecordCopyValue(loopingPerson, kABPersonFirstNameProperty);
NSString *name=(__bridge NSString *)(firstName);
if([name isEqualToString:@"VizziCal"])
break;
}
if(loopingPerson !=NULL )
{
[prefs setBool:YES forKey:@"contact-created"];
CFDataRef dataRef = (__bridge CFDataRef)(UIImagePNGRepresentation(imgdata));
//Phone number is a list of phone number, so create a multivalue
ABMutableMultiValueRef phoneNumberMultiValue =
ABMultiValueCreateMutable(kABPersonPhoneProperty);
ABMultiValueAddValueAndLabel(phoneNumberMultiValue ,(__bridge CFTypeRef)(incoming_number),kABPersonPhoneMobileLabel, NULL);
// ...
// Set other properties
ABRecordSetValue(newPerson, kABPersonPhoneProperty, phoneNumberMultiValue, &myError);
// ...
ABAddressBookAddRecord(addressBook, newPerson, &myError);
ABAddressBookSave(addressBook, &myError);
if (myError != NULL)
{
CFStringRef errorDesc = CFErrorCopyDescription(myError);
NSLog(@"Contact not saved: %@", errorDesc);
CFRelease(errorDesc);
}
if (ABPersonSetImageData(newPerson, dataRef, &myError)) {
if (ABAddressBookHasUnsavedChanges(addressBook)) {
NSLog(@"has unsaved changes");
} else {
NSLog(@"nothing to save");
}
if (ABAddressBookSave(addressBook, &myError)) {
NSLog(@"saved");
} else {
NSLog(@"not saved");
}
}
CFRelease(newPerson);
CFRelease(addressBook);
CFRelease(phoneNumberMultiValue);
}
}
}
}
}
-(void)设置联系人:(UIImage*)imgdata:(NSString*)传入的\u号码{
ABRecordRef person=NULL;
ABRecordRef loopingPerson=NULL;
_Bool vizzical_present=假;
CFErrorRef myError=NULL;
NSArray*所有联系人;
ABAddressBookRef addressBook=ABAddressBookCreateWithOptions(NULL,&myError);
//ABAddressBookRef addressBook=ABAddressBookCreateWithOptions(无,无);
__block BOOL accessgrated=否;
如果(ABAddressBookRequestAccessWithCompletion!=NULL){//我们在iOS 6上
dispatch\u semaphore\u t sema=dispatch\u semaphore\u create(0);
ABAddressBookRequestAccessWithCompletion(addressBook,^(已授予bool,CFErrorRef错误){
accessgrated=已授予;
调度信号量信号(sema);
});
调度信号量等待(永远调度时间);
//调度发布(sema);
}
否则{//我们使用的是iOS 5或更高版本
accessgrated=是;
}
如果(已授予访问权限){
//int count=(int)ABAddressBookGetPersonCount(addressBook);
所有触点=(u_桥_传输阵列)
*)ABAddressBookCopyArrayFallPeople(地址簿);
对于(CFIndex i=1;i 如果(imgdata.size.height首先执行所有这些操作来获取传入的No
,请尝试为该定制负载
这很简单
看一看
你可以试试:
{ "alert": "Please help me", "phone": "9999999999" }
注意:这将在服务器端创建。应用程序因exc\u bad\u访问而崩溃,因为您发布了objcet,然后它仍在使用中,这就是发生此错误的原因。可能重复的问题多次不发布相同的问题!错误在我得到的地方,该对象仍然存在,我可以在中看到debugger@Kerni我的问题还没有解决ved..我正在获取有效负载,请查看以下内容:收到的通知:{aps={alert=“Let us talk-+918884718240”;sound=“beep.caf”;};}我知道你得到了什么。现在你得到了这个号码,但是使用自定义的有效载荷。因此,在这个号码中不会出现崩溃或任何对象释放的问题。但是如何调用DidReceiveEmotentification?不推?现在告诉你如何得到收到的通知:{aps={alert=“Let us talk-+918884718240”;sound=“beep.caf”};}
this??但对于相同的负载,它在第一次迭代中工作正常,当我添加联系人时,在下一次迭代中出现错误,可能是发布了一些内容。