2016-12-15 139 views
1

对不起,但我总是Noob,而不是程序员。我在模板上创建了一个照片编辑应用程序,并在Google搜索,教程等帮助下大量定制。Xcode iOS应用程序挂在启动屏幕上“semaphore_wait_trap()”

使用Xcode 7.3.1,iOS 9.3,较新的Photosframework和唯一的目标C. 我已将应用程序指向某一点除了我注意到第一次启动时,应用程序挂起(调试报告semaphore_wait_trap())

该应用程序无法进入下一步“请求访问照片”警报弹出在iOS 9.3,唯一的办法是点击主页按钮,然后看到授权访问警报,然后切换回应用程序,然后退出应用程序,重新加载它,然后在超时后运行良好,这当然不是理想的用户体验。

我看看,如果我在调试模式下暂停其挂在:“semaphore_wait_trap()”

伊夫一派,搜索天,不能找到一个解决方案,以获得许可警报弹出展现在我的应用程序窗口的顶部。

它超越了我。任何想法将不胜感激。

查看弹出窗口上保留的启动图像的屏幕截图。

如果按“主页”按钮,警报授予出现访问照片。

应用程序的委托:

@implementation AppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){ 
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]]; 
} 
UILocalNotification *locationNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; 
if (locationNotification) { 
    // Sets icon badge number to zero 
    application.applicationIconBadgeNumber = 0; 
} 
// END Local Notification ========================== 


return true; 

} 

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { 

// Resets icon's badge number to zero 
application.applicationIconBadgeNumber = 0; 

} 

这里是主视图控制器的一个片段(希望这不是长,不知道问题出在哪里)

HomeVC.m:

#import "HomeVC.h" 
#import "Configs.h" 
#import "AAPLGridViewCell2.h" 
#import "NSIndexSet+Convenience.h" 
#import "UICollectionView+Convenience.h" 
#import "AAPLRootListViewController.h" 
#import "Configs.h" 
#import "ImageEditorTheme.h" 
#import "ImageEditorTheme+Private.h" 

@import PhotosUI; 
@import UIKit; 


@interface HomeVC() 
< 
PHPhotoLibraryChangeObserver, 
UICollectionViewDelegateFlowLayout, 
UICollectionViewDataSource, 
UICollectionViewDelegate 
> 
@property (nonatomic, strong) NSArray *sectionFetchResults; 
@property (nonatomic, strong) NSArray *sectionLocalizedTitles; 
@property (nonatomic, strong) PHCachingImageManager *imageManager; 
@property CGRect previousPreheatRect; 
@property (nonatomic, strong) IBOutlet UICollectionViewFlowLayout *flowLayout; 

@property (nonatomic, assign) CGSize lastTargetSize; 


@end 


@implementation HomeVC 

{ 
    UIActivityIndicatorView *_indicatorView; 
} 

static NSString * const AllPhotosReuseIdentifier = @"AllPhotosCell"; 
static NSString * const CollectionCellReuseIdentifier = @"CollectionCell"; 

static NSString * const CellReuseIdentifier = @"Cell"; 
static CGSize AssetGridThumbnailSize; 


- (void)awakeFromNib { 

    self.imageManager = [[PHCachingImageManager alloc] init]; 
    [self resetCachedAssets]; 

    [[PHPhotoLibrary sharedPhotoLibrary] registerChangeObserver:self]; 

} 

- (void)dealloc { 
    [[PHPhotoLibrary sharedPhotoLibrary] unregisterChangeObserver:self]; 
} 

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 


    _logoImage.layer.cornerRadius = 30; 
    [self loadPhotos]; 

    [_libraryOutlet addTarget:self action:@selector(touchUp:) forControlEvents:UIControlEventTouchUpInside]; 

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handle_data) name:@"reload_data" object:nil]; 

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hideMenu) name:@"hide_menu" object:nil]; 

} 

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 

    // Begin caching assets in and around collection view's visible rect. 
    [self updateCachedAssets]; 
} 

-(void)handle_data { 
    //[self.collectionView2 layoutIfNeeded]; 
    //[self resetCachedAssets]; 

    [self.collectionView2 reloadData]; 
    [self updateCachedAssets]; 
    NSLog(@"did it work?"); 
} 

- (void)viewDidLayoutSubviews 
{ 
    NSInteger section = [self.collectionView2 numberOfSections] - 1; 
    NSInteger item = [self.collectionView2 numberOfItemsInSection:section] - 1; 
    NSIndexPath *indexPath = [NSIndexPath indexPathForItem:item inSection:section]; 
    [self.collectionView2 scrollToItemAtIndexPath:indexPath atScrollPosition:(UICollectionViewScrollPositionTop) animated:NO]; 
    //[self loadPhotos]; 
} 

-(void) loadPhotos { 

    PHFetchOptions *allPhotosOptions = [[PHFetchOptions alloc] init]; 
    allPhotosOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]]; 

    PHFetchResult *allPhotos = [PHAsset fetchAssetsWithOptions:allPhotosOptions]; 


    if (self.assetsFetchResults == nil) { 
     self.assetsFetchResults = allPhotos; 
    } 
} 



#pragma mark - PHPhotoLibraryChangeObserver 

- (void)photoLibraryDidChange:(PHChange *)changeInstance { 
    // Check if there are changes to the assets we are showing. 
    PHFetchResultChangeDetails *collectionChanges = [changeInstance changeDetailsForFetchResult:self.assetsFetchResults]; 
    if (collectionChanges == nil) { 
     return; 
    } 

    /* 
    Change notifications may be made on a background queue. Re-dispatch to the 
    main queue before acting on the change as we'll be updating the UI. 
    */ 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     // Get the new fetch result. 
     self.assetsFetchResults = [collectionChanges fetchResultAfterChanges]; 

     UICollectionView *collectionView = self.collectionView; 

     if (![collectionChanges hasIncrementalChanges] || [collectionChanges hasMoves]) { 
      // Reload the collection view if the incremental diffs are not available 
      [collectionView reloadData]; 

     } else { 
      /* 
      Tell the collection view to animate insertions and deletions if we 
      have incremental diffs. 
      */ 
      [collectionView performBatchUpdates:^{ 
       NSIndexSet *removedIndexes = [collectionChanges removedIndexes]; 
       if ([removedIndexes count] > 0) { 
        [collectionView deleteItemsAtIndexPaths:[removedIndexes aapl_indexPathsFromIndexesWithSection:0]]; 
       } 

       NSIndexSet *insertedIndexes = [collectionChanges insertedIndexes]; 
       if ([insertedIndexes count] > 0) { 
        [collectionView insertItemsAtIndexPaths:[insertedIndexes aapl_indexPathsFromIndexesWithSection:0]]; 
       } 

       NSIndexSet *changedIndexes = [collectionChanges changedIndexes]; 
       if ([changedIndexes count] > 0) { 
        [collectionView reloadItemsAtIndexPaths:[changedIndexes aapl_indexPathsFromIndexesWithSection:0]]; 
       } 
      } completion:NULL]; 
     } 

     [self resetCachedAssets]; 
    }); 
} 



#pragma mark - UICollectionViewDataSource 

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 
    return self.assetsFetchResults.count; 
} 

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath; { 

    CGFloat colum = 3.0, spacing = 0.0; 
    CGFloat value = floorf((CGRectGetWidth(self.view.bounds) - (colum - 1) * spacing)/colum); 

    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; 
    layout.itemSize      = CGSizeMake(value, value); 
    layout.sectionInset     = UIEdgeInsetsMake(0, 0, 0, 0); 
    layout.minimumInteritemSpacing  = spacing; 
    layout.minimumLineSpacing   = spacing; 


    return CGSizeMake(value, value); 
    //return self.collectionView.frame.size; 
} 


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 

    PHAsset *asset = self.assetsFetchResults[indexPath.item]; 

    // Dequeue an AAPLGridViewCell. 
    AAPLGridViewCell2 *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellReuseIdentifier forIndexPath:indexPath]; 
    cell.representedAssetIdentifier = asset.localIdentifier; 


    // Request an image for the asset from the PHCachingImageManager. 
    [self.imageManager requestImageForAsset:asset 
           targetSize:CGSizeMake(130, 130) 
           contentMode:PHImageContentModeAspectFill 
            options:nil 
           resultHandler:^(UIImage *result, NSDictionary *info) { 
            // Set the cell's thumbnail image if it's still showing the same asset. 
            if ([cell.representedAssetIdentifier isEqualToString:asset.localIdentifier]) { 
             cell.thumbnailImage = result; 
            } 
           }]; 
    CGPoint bottomOffset = CGPointMake(-0, self.collectionView.contentSize.height - self.collectionView.bounds.size.height + self.collectionView.contentInset.bottom); 
    [self.collectionView setContentOffset:bottomOffset animated:NO];; 
     return cell; 

} 

- (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Prepare the options to pass when fetching the live photo. 
    PHAsset *asset = self.assetsFetchResults[indexPath.item]; 
    PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init]; 
    options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat; 
    options.networkAccessAllowed = NO; 

    dispatch_async(dispatch_get_main_queue(), ^{ 
     _indicatorView = [ImageEditorTheme indicatorView]; 
     _indicatorView.center = self.containerView.center; 
     [self.containerView addSubview:_indicatorView]; 
     [_indicatorView startAnimating]; 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
    PreviewVC *prevVC = (PreviewVC *)[storyboard instantiateViewControllerWithIdentifier:@"PreviewVC"]; 

    [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeAspectFit options:options resultHandler:^(UIImage *result, NSDictionary *info) { 


      // Show the UIImageView and use it to display the requested image. 
      passedImage = result; 

      prevVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
      [self presentViewController:prevVC animated:true completion:nil]; 
     [_indicatorView stopAnimating]; 
     }]; 
    }); 
} 


#pragma mark - UIScrollViewDelegate 

- (void)scrollViewDidScroll:(UIScrollView *)scrollView { 

    // Update cached assets for the new visible area. 
    [self updateCachedAssets]; 
} 
+0

没有人有任何建议吗? –

+0

你需要提供或者一些截图或代码,使乌拉圭回合的主要问题可以得到正确的理解.. –

+0

或提供乌尔应用程序委托类代码... –

回答

0

我设法解决了这个问题。这很简单,只需删除对“[self resetCachedAssets];” in“awakeFromNib”

现在很好用。

相关问题