Xcode iOS应用程序挂在启动屏幕“semaphore_wait_trap()”

时间:2016-12-15 07:05:41

标签: objective-c xcode permissions alert hang

对不起,但我是Noob,而不是程序员。我在模板上设置了一个照片编辑应用程序,并在Google搜索,教程等的帮助下对其进行了大量定制。

使用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];
}

1 个答案:

答案 0 :(得分:0)

我设法解决了这个问题。就像删除对“[self resetCachedAssets];”的调用一样简单。在“awakeFromNib”中

现在很棒。