小编Mat*_*ieu的帖子

等待assetForURL块完成

我想等待这个代码继续执行之前继续但是因为这些块被异步调用我不知道该怎么做???

NSURL *asseturl;
NSMutableArray *tmpListAsset = [[NSMutableArray alloc] init];

ALAssetsLibrary *library = [[[ALAssetsLibrary alloc] init] autorelease];
NSMutableArray *objectsToRemove = [[NSMutableArray alloc] init];
for (NSDictionary *dico in assetsList) {
    asseturl = [NSURL URLWithString:[dico objectForKey:@"assetUrl"]];
    NSLog(@"asset url %@", asseturl);
    // Try to load asset at mediaURL
    [library assetForURL:asseturl resultBlock:^(ALAsset *asset) {
        // If asset doesn't exists
        if (!asset){
            [objectsToRemove addObject:dico];
        }else{
            [tmpListAsset addObject:[asseturl absoluteString]];
            NSLog(@"tmpListAsset : %@", tmpListAsset);
        }
    } failureBlock:^(NSError *error) {
        // Type your code here for failure (when user …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c alasset alassetslibrary

24
推荐指数
2
解决办法
1万
查看次数

如何使用URL检查ALAsset是否仍然存在

我有一个包含ALAsset网址的数组(不是完整的ALAsset对象)因此,每次启动我的应用程序时,我都要检查我的数组,看看它是否仍然是最新的...

所以我试过了

NSData *assetData = [[NSData alloc] initWithContentsOfFile:@"assets-library://asset/asset.PNG?id=1000000001&ext=PNG"];
Run Code Online (Sandbox Code Playgroud)

但是资产数据总是零

thx的帮助

iphone alasset alassetslibrary

11
推荐指数
3
解决办法
1万
查看次数

iphone navigationController:在退出当前视图之前等待uialertview响应

我有一个带有导航控制器管理的后退按钮的视图,我想检查用户单击后退按钮时是否已保存文件.如果文件已保存,则返回上一个视图,否则uialertview会询问您是否要保存文件.

所以我这样做了,但视图消失了,警报视图出现了.

-(void)viewWillDisappear:(BOOL)animated {
if(!self.fileSaved){
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Save the file?"  delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes",nil];
    [alert show];
    [alert release];
}
}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
    case 0:
        NSLog(@"NO");
        break;
    case 1:
        NSLog(@"yes");
        break;
    default:
        break;
}
}
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uinavigationcontroller uialertview

6
推荐指数
1
解决办法
7475
查看次数

回形针将图像保存为jpg与白色背景

我想知道如何将带有alpha通道的png和gif文件转换为带有paperclip的白色背景的jpg

我试过这个但是,它不起作用

has_attached_file( 
  :photo, 
  :whiny => false, 
  :styles => { 
    :medium => ["300x300>", :jpg], 
    :thumb => ["100x100>", :jpg] 
  }, 
  :convert_options => { :all => '-alpha white -background white'}
)
Run Code Online (Sandbox Code Playgroud)

它以灰色背景保存文件.

imagemagick paperclip post-processing

5
推荐指数
2
解决办法
3605
查看次数

Ruby on rails - Authlogic:定期检查用户会话是否有效

我正在寻找一个解决方案,允许我定期检查用户会话是否已过期,如果是,则将其重定向到登录页面.
我正在使用Authlogic gem,所以我正在做的是调用一个在current_user上进行测试的函数.
我的USER_SESSION_TIMEOUT是5分钟,所以我每隔5:10分钟进行一次这个ajax调用.

<%= periodically_call_remote :url => {:controller => 'user_session', :action => 'check_session_timed_out'}, :frequency =>  (USER_SESSION_TIMEOUT + 10.seconds) %>
Run Code Online (Sandbox Code Playgroud)
def check_session_timed_out
   if !current_user
      flash[:login_notice] = "Your session timed out due to a period of inactivity. Please sign in again."
      render :update do |page|
          page.redirect_to "/user_sessions/new"   
      end
   else
       render :nothing => true
   end
end
Run Code Online (Sandbox Code Playgroud)

我注意到每次调用current_user时,用户对象都会更新,因此会话更新为5分钟.
打开一个选项卡时没有问题但是如果每次调用check_session_timed_out时都有2个选项卡,则current_user将更新用户,因此会话永不过期.

任何的想法?谢谢

session ruby-on-rails session-timeout authlogic

5
推荐指数
2
解决办法
3913
查看次数

在iPhone中创建一个目录

这有什么问题?

#define AUDIO_NOTES_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/myApp/Pictures"]

NSFileManager *NSFm= [NSFileManager defaultManager]; 
BOOL isDir=YES;

if(![NSFm fileExistsAtPath:FILEPATH isDirectory:&isDir])
    if(![NSFm createDirectoryAtPath:FILEPATH attributes:nil])
        NSLog(@"Error: Create folder failed");
Run Code Online (Sandbox Code Playgroud)

filesystems iphone objective-c nsfilemanager

2
推荐指数
2
解决办法
2万
查看次数

当文件不是有效的附件内容类型时,Paperclip :: NotIdentifiedByImageMagickError

当我尝试上传不在的文件时,我系统地出错了 ["image/jpg", "image/jpeg", "image/gif", "image/png", "image/pjpeg", "image/x-png"]

当我尝试上传像'wav'这样的文件时,我收到了这条消息

* Photo /var/folders/nT/nTr21TWfFRO7r3cyG-h-7++++TM/-Tmp-/Clip audio 01,39154,0.wav is not recognized by the 'identify' command. * Photo /var/folders/nT/nTr21TWfFRO7r3cyG-h-7++++TM/-Tmp-/Clip audio 01,39154,0.wav is not recognized by the 'identify' command. * Photo content type Accepted files include: jpg, gif, png

因此,它检测到该文件不是图像并显示我的消息,"Accepted files include: jpg, gif, png"但我有这个额外的消息包括在我的照片无法通过'识别'命令识别...上传工作正常的图片

我的代码是:

控制器:

def upload  
  @picture= Picture.new(params[:picture])  
    if !@picture.valid?  
        render  :form  
    end  
end  
Run Code Online (Sandbox Code Playgroud)

查看表格:

<%= error_messages_for :picture, :header_message => nil, :message => nil %>  
<% form_for :picture, @picture, :name => "uploadPic", …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails attachment paperclip

2
推荐指数
1
解决办法
3559
查看次数

指针数组导致泄漏

- (无效)setUserFilters {

    //init the user filters array
    userFilters = [[NSMutableArray alloc] init];
    SearchCriteria *tmpSc= [[SearchCriteria alloc] init];
    for(int i=0;i<[searchFilters count];i++)
    {
    tmpSc=[self.searchFilters objectAtIndex:i];
    if(tmpSc.enabled==TRUE)
        [userFilters addObject:tmpSc];
    }
    }
Run Code Online (Sandbox Code Playgroud)

searchFilters是可以设置为true或false的过滤器列表,我使用userFilters使用仅设置为TRUE的过滤器填充表视图

但是行SearchCriteria*tmpSc = [[SearchCriteria alloc] init]; 导致泄漏,我不知道如何解决,因为如果我在函数结束时释放我松开指针,它崩溃

有任何想法吗?

arrays pointers memory-leaks objective-c

1
推荐指数
1
解决办法
239
查看次数

为什么这个Core Data示例崩溃了?

我有一个模型,我有一个Person实体和一个Picture实体.在我的Picture实体中,我有一个与Person关系的属性.

我想有一个关于如何将图片添加到Person的示例,因为我所做的不起作用.

-(BOOL)savePicture:(NSString *)urlPicture:(Person *)person{
SettingsSingleton *userSettings = [SettingsSingleton sharedManager];    
NSManagedObjectContext *managedObjectContext = [userSettings managedObjectContext]; 
NSEntityDescription *myContentEntity = [NSEntityDescription entityForName:@"Pictures" inManagedObjectContext:managedObjectContext];
NSManagedObject *contentToSave = [[NSManagedObject alloc] initWithEntity:myContentEntity insertIntoManagedObjectContext:managedObjectContext];

[contentToSave setValue:urlPicture forKey:@"url"];
[contentToSave setValue:person forKey:@"relatedPerson"];

[managedObjectContext insertObject:contentToSave];  

NSError *error;
if ([managedObjectContext save:&error]){
    //Deal with errors
    NSLog(@"Error");
            return NO; 
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)

它在行上崩溃if([managedObjectContext save:&error])并且在控制台中我有这些错误:

-[UITableViewCell objectID]: unrecognized selector sent to instance 0x135c2b0 Serious application error.  Exception was caught during Core Data change processing: ***     
-[UITableViewCell objectID]: unrecognized selector sent to instance …
Run Code Online (Sandbox Code Playgroud)

entity-relationship core-data objective-c

0
推荐指数
1
解决办法
1万
查看次数