2014-09-22 4 views
1

, 내가하지만 어떻게든지 그것을 초기화하는 여러 가지 방법을 시도 내 애플 리케이션 냉동 또는 다른 무작위로 내 응용 프로그램 동결하는 것 :ABPeoplePickerNavigationController 내가 ABPeoplePickerNavigationController 좀비를 생성하고 내 응용 프로그램을 동결에 문제가

if([appDelegate testInternetConnection]){ 

     ABPeoplePickerNavigationController *picker =[[ABPeoplePickerNavigationController alloc] init]; 
     [picker setPeoplePickerDelegate:self]; 
     [self presentViewController:picker animated:YES completion:nil ]; 
    }else{ 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Internet Connection Error" message:@"This App needs internet in order to work, please make sure you are connected to a valid network" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil]; 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      // Display/dismiss your alert 
      [alert show]; 

     }); 


    } 

을 내가하지 내가 뭘 잘못하고 있는지 알지만 내 응용 프로그램을 에뮬레이터 외부로 또는 장치가 디버깅하지 않을 때 얼어 버릴 수 있습니다. 그 이유는 무엇입니까? 여기 -Update

내가 엑스 코드에 연결된 실행 때 정지하지 않는 지금 말했듯이 코어 데이터

#pragma mark Save data to Core Data Safely 
-(void) saveData{ 
    NSPersistentStoreCoordinator *mainThreadContextStoreCoordinator = [appDelegate persistentStoreCoordinator]; 
    dispatch_queue_t request_queue = dispatch_queue_create("com.4Postcards.savingData", NULL); 
    dispatch_async(request_queue, ^{ 

     // Create a new managed object context 
     // Set its persistent store coordinator 
     NSManagedObjectContext *newMoc = [[NSManagedObjectContext alloc] init]; 

     [newMoc setPersistentStoreCoordinator:mainThreadContextStoreCoordinator]; 

     // Register for context save changes notification 
     NSNotificationCenter *notify = [NSNotificationCenter defaultCenter]; 
     [notify addObserver:self 
        selector:@selector(mergeChanges:) 
         name:NSManagedObjectContextDidSaveNotification 
        object:newMoc]; 

     // Do the work 
     // Your method here 
     // Call save on context (this will send a save notification and call the method below) 
     NSError *error; 
     BOOL success = [newMoc save:&error]; 
     if (!success) 
      NSLog(@"%@",error); 
     // Deal with error 
    }); 
} 

- (void)mergeChanges:(NSNotification*)notification 
{ 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     NSLog(@"Data Saved"); 

    }); 
} 

에 저장 사용하고 코드이지만, 분리 할 때 그렇습니다

+0

당신이 응용 프로그램에서 coredata을 사용하는 ?? – Saad

+0

연락처를 선택하기 위해 인터넷이 필요한 이유가 무엇입니까? – rmaddy

+0

디버거를 사용하여 앱이 "고정 된 위치"를 확인해 보셨습니까? – rmaddy

답변

0

핵심 데이터 때문입니다. 데이터를 변경 (예 : 업데이트, 삭제, 개체 추가) 할 때마다 기억하십시오. 같은 persistentStoreCoordinator로 새로운 ManagedObjectContext를 작성합니다. Didsave 통지 옵저버를 코어 데이터에 추가하십시오. 기본적으로 핵심 데이터는 스레드로부터 안전하지 않습니다. 그리고 thread1이 entity1의 데이터를 요청하고 동시에 thread2가 entity1에 데이터를 추가하고 thread3이 entry1에서 데이터를 삭제한다고 가정 해 보겠습니다. 동시성이 관리되지 않기 때문에 실행이 중지됩니다. 당신은 더 나은 이해와 샘플 코드를 볼 수 있도록 이러한 링크를 연구하는 것입니다.

Apple Developer Concurrency with Core Data

Sample Code Apple Developer

StackoverFlow Detail

A blog with code examples

+0

안녕하세요! 큰 반향을 불러 일으켰지 만 여전히 동일한 문제로 코어 데이터에 데이터를 저장하는 방식을 변경했으며 이제는 Xcode에 연결되지 않은 경우에만 동일한 지점에서 고정됩니다. – ZurceZx

+0

핵심 데이터에 대한 코드를 작성하십시오 – Saad

+0

코드 – ZurceZx