1

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];

        });


    }

何が間違っているのかわかりませんが、これはエミュレータの外でアプリをフリーズさせているか、デバイスがデバッグしていないときにフリーズしています。理由はありますか?

-アップデート

Core Dataに保存するために使用しているコードは次のとおりです

#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");

    });
}

私が今言ったように、Xcodeに接続して実行しているときはフリーズしませんが、切断するとフリーズします

4

1 に答える 1

0

それはコアデータによるものです。データへの変更 (更新、削除、オブジェクトの追加など) を開始するたびに覚えておいてください。同じpersistentStoreCoordinatorで新しいManagedObjectContextを作成してください。そして、Didsave 通知オブザーバーをコア データに追加します。基本的に何が起こるかというと、コア データはスレッド セーフではありません。そして、スレッド 1 がエンティティ 1 にデータを要求し、同時にスレッド 2 がエンティティ 1 にデータを追加し、スレッド 3 がエントリ 1 からデータを削除するとします。同時実行が管理されていないため、実行は停止されます。これらのリンクを調べて理解を深め、サンプル コードも参照してください。

コア データを使用した Apple Developer Concurrency

サンプル コード Apple Developer

StackoverFlow の詳細

コード例を含むブログ

于 2014-09-23T00:58:28.407 に答える