使用NSPredicate与照片框架的异常:定义 - [NSFunctionExpression constantValue]!

时间:2015-11-17 23:55:37

标签: nspredicate photokit phasset

以下代码在对fetchAssetsWithOptions的调用上抛出NSInvalidArgumentException:

PHFetchOptions *allPhotosOptions = [[PHFetchOptions alloc] init];
allPhotosOptions.sortDescriptors =
        @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
allPhotosOptions.predicate = 
        [NSPredicate predicateWithFormat:@"pixelHeight >=  pixelWidth * 1.95" ];
self.allPhotos = [PHAsset fetchAssetsWithOptions:allPhotosOptions];

消息是

NSInvalidArgumentException ... reason: '*** -constantValue only defined for abstract class.  
    Define -[NSFunctionExpression constantValue]!'

我在谓词格式字符串上尝试了很多变体,但是当我尝试使用乘法时总是得到这个消息。我做错了什么?

1 个答案:

答案 0 :(得分:0)

我不确定为什么,但是当你没有将任何格式参数传递给predicateWithFormat时:并将它与Photos一起使用就会出现这个错误;

我能够通过确保传递格式参数来解决问题。所以在你的情况下:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<header class="bgimage">
  <img src='http://placehold.it/400x400/f00' alt="Junebug Mixology" class="img-responsive center-block img-circle" />
</header>

<div class="container-fluid">
  <div class="row">
    <section class="hello col-md-5">
      <h1>hello!</h1>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab libero, cupiditate veniam officiis itaque in porro iure fugit iusto reprehenderit commodi earum cum blanditiis quos error similique quod, facere! Hic.</p>
    </section>

    <section class="social-media col-md-4 col-md-offset-3">
      <h3>To Stay Connected</h3>
      <a href="https://www.instagram.com/neon.honey/" target="_blank">
        <img class="media-object" src="http://placehold.it/25x25/ff0" alt="Instagram">
      </a>
      <a href="https://twitter.com/deephoney/" target="_blank">
        <img class="media-object" src="http://placehold.it/25x25/ff0" alt="Twitter">
      </a>
      <a href="https://www.pinterest.com/electrodextrose/" target="_blank">
        <img class="media-object" src="http://placehold.it/25x25/ff0" alt="Pinterest" />
      </a>
      <a href="mailto:" target="_top"><span class="glyphicon glyphicon-envelope" aria-hidden="true"></span></a>
    </section>
  </div>
</div>