gpt4 book ai didi

cocoa-touch - Runloop 在模拟器上工作在设备上失败

转载 作者:行者123 更新时间:2023-11-29 05:07:37 24 4
gpt4 key购买 nike

我有一台 iPod Touch 第 2 代,我正在尝试使用照片名称从资源库中检索照片。我在设备上运行了恢复以确保它是出厂版本 4.1。

我的头文件有:

#import <AssetsLibrary/AssetsLibrary.h>
{
BOOL fetching;
}
@property BOOL fetching;


typedef void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *asset);
typedef void (^ALAssetsLibraryAccessFailureBlock)(NSError *error);

我的代码是:

- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSArray *array = [info allKeys];
for (NSString *str in array) NSLog(@"Key = %@", str);

// iPad uses UIImagePickerControllerMediaURL
// iPhone uses UIImagePickerControllerReferenceURL

NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL];

fetching = NO;
NSLog(@"1 fetching = %d", fetching);
[self photoFromURL:url];
NSLog(@"2 fetching = %d", fetching);
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
NSLog(@"3 fetching = %d", fetching);
while (!fetching && [runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
NSLog(@"4 fetching = %d", fetching);

...

photoFromURL 的位置

- (void) photoFromURL:(NSURL *)inURL
{
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
if (iref)
{
photo = [UIImage imageWithCGImage:iref];
[photo retain];
fetching = YES;
}
};

ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"Cannot get image - %@",[myerror localizedDescription]);
};

ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
[assetslibrary assetForURL:inURL
resultBlock:resultblock
failureBlock:failureblock];
}

这在模拟器上运行良好,但运行循环永远不会在设备上返回。我完成了前三个 NSLog 语句以进行提取,但第四个从未出现。

请帮忙。- 丹

最佳答案

定位服务???

我发现我必须在设备上启用定位服务。我从来没有想过我需要定位服务来访问照片库。我想它们都在新的资源库中。

我将其关闭,因为 iOS 4.0+ 耗尽了 iPod touch 电池。

关于cocoa-touch - Runloop 在模拟器上工作在设备上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4017188/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com