300 件の連絡先で同じ問題が発生し、約 5 分かかりました。パッチを適用した後、わずか 10 秒しかかかりません。
これが私のプルリクエストです: https://github.com/phonegap/phonegap/pull/19
彼らは各写真の一時ファイルを生成する必要があり、狂ったループを使用して空きファイル パスを見つけています。何かのようなもの :
do {
filePath = [NSString stringWithFormat:@"%@/photo_%03d.jpg", docsPath, i++];
} while ([fileMgr fileExistsAtPath:filePath]);
今はmktempを使用しており、すべてが高速です。
フル解像度の写真が必要ない場合は、以下を置き換えることもできます:
CFDataRef photoData = ABPersonCopyImageData(self.record);
に :
CFDataRef photoData = ABPersonCopyImageDataWithFormat(self.record, kABPersonImageFormatThumbnail);
それがあなたを助けることを願っています!
編集 :
IOS は、アプリケーションを起動するたびに一時ディレクトリをフラッシュします。
作成した一時ファイルは、お客様の責任で削除してください。システムは起動時にそれらをクリーンアップしますが、それには非常に長い時間がかかる可能性があります.
から: http://cocoadev.com/wiki/NSTemporaryDirectory
アプリケーションのブートストラップを遅くしたくない場合は、連絡先 ID に基づいて常に同じファイルパスを使用する必要があります。ファイルが既に存在する場合は、クリーンアップと書き込みの時間を節約できます。
- (NSObject*)extractPhotos
{
NSMutableArray* photos = nil;
if (ABPersonHasImageData(self.record)) {
//CFDataRef photoData = ABPersonCopyImageDataWithFormat(self.record, kABPersonImageFormatThumbnail);
CFDataRef photoData = ABPersonCopyImageData(self.record);
NSData* data = (__bridge NSData*)photoData;
// write to temp directory and store URI in photos array
// get the temp directory path
NSString* docsPath = [NSTemporaryDirectory ()stringByStandardizingPath];
NSError* err = nil;
int recordId = ABRecordGetRecordID(self.record);
NSFileManager* fileMgr = [[NSFileManager alloc] init];
NSString* filePath = [NSString stringWithFormat:@"%@/photo_%03d.jpg", docsPath, recordId];
BOOL hasImage = NO;
if ([fileMgr fileExistsAtPath:filePath]) {
hasImage = YES;
} else if ([data writeToFile:filePath options:NSAtomicWrite error:&err]) {
hasImage = YES;
}
if (hasImage) {
photos = [NSMutableArray arrayWithCapacity:1];
NSMutableDictionary* newDict = [NSMutableDictionary dictionaryWithCapacity:2];
[newDict setObject:filePath forKey:kW3ContactFieldValue];
[newDict setObject:@"url" forKey:kW3ContactFieldType];
[newDict setObject:@"false" forKey:kW3ContactFieldPrimary];
[photos addObject:newDict];
}
CFRelease(photoData);
}
return photos;
}
編集 (2013 年 8 月 1 日) : 参考までに: コルドバにマージ: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/c6a1dbe3