- (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (_persistentStoreCoordinator != nil) { return _persistentStoreCoordinator; } NSURL *oldStoreURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Test.sqlite"]; NSURL *storeURL = [NSURL fileURLWithPath: [[self applicationSupportDirectory] stringByAppendingPathComponent: @"Test.sqlite"]]; NSFileManager* fileManager = [NSFileManager defaultManager]; NSError *error = nil; NSString *oldString = [oldStoreURL path]; NSString *newString = [storeURL path]; if([fileManager fileExistsAtPath:oldString]) { if (![fileManager moveItemAtPath:oldString toPath:newString error:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } NSString *oldString2 = [oldString stringByAppendingString:@"-shm"]; NSString *newString2 = [newString stringByAppendingString:@"-shm"]; if (![fileManager moveItemAtPath:oldString2 toPath:newString2 error:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } oldString2 = [oldString stringByAppendingString:@"-wal"]; newString2 = [newString stringByAppendingString:@"-wal"]; if (![fileManager moveItemAtPath:oldString2 toPath:newString2 error:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } } _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } return _persistentStoreCoordinator; }
NSRange dataRange; NSInteger dataSize = pinData.length; NSInteger dataSplitCount = dataSize/DATA_SPLIT_SIZE; dataRange.length = DATA_SPLIT_SIZE; dataRange.location = 0; NSMutableArray *dataArray = [NSMutableArray array]; for(NSInteger cnt = 0;cnt<dataSplitCount;cnt++) { [dataArray addObject:[sendData subdataWithRange:dataRange]]; dataRange.location += DATA_SPLIT_SIZE; } // 最後のデータは、レングスを調整してから処理を行う dataRange.length = dataSize%DATA_SPLIT_SIZE; [dataArray addObject:[pinData subdataWithRange:dataRange]];
NSMutableData *receiveData;
// 受信データを保存する [receiveData appendData:data];
DataObject *receiveObject = [NSKeyedUnarchiver unarchiveObjectWithData: receiveData];
- (void)peerPickerController:(GKPeerPickerController *)picker didConnectPeer:(NSString *)peerID toSession:(GKSession *)session { // セッションを保管 currentSession = session; // デリゲートのセット session.delegate = self; // データ受信時のハンドラを設定 [session setDataReceiveHandler:self withContext:nil]; // ピアピッカーを閉じる picker.delegate = nil; [picker dismiss]; if (osVersion >= 7.0) { // iOS7.0 if (self.isConnecting == NO) [self session:currentSession peer:peerID didChangeState:GKPeerStateConnected]; } } - (void)session:(id)session peer:(id)peerID didChangeState:(GKPeerConnectionState)state { switch (state) { case GKPeerStateAvailable: // (省略) break; case GKPeerStateConnecting: // (省略) break; case GKPeerStateConnected: // 接続完了 self.isConnecting = YES; // 接続完了後の処理をここに書く(省略) break; case GKPeerStateDisconnected: // (省略) break; case GKPeerStateUnavailable: // (省略) break; default: break; } }