项目中遇到的问题

1.iOS中,延时调用不会因为对象的销毁而失效,如果不作取消处理,可能会造成程序功能混乱。

2.在接收到新聊天消息,并且滚动到底部过程中,会出现闪动的问题,这是因为在iOS11后,系统默认会有预估高度导致的,解决办法是让系统的预估高度设置为0。

 if (@available(iOS 11.0, *)) {

        _palmistryAnalyzeTableView.estimatedRowHeight = 0;

        _palmistryAnalyzeTableView.estimatedSectionFooterHeight = 0;

        _palmistryAnalyzeTableView.estimatedSectionHeaderHeight = 0;
    }

3.关于根据周围环境光照亮度开始闪光灯问题:是在已有的会话基础上在增加一个AVCaptureVideoDataOutput输出对象,通过代理回调,拿到光照亮度系数去做处理。

- (AVCaptureVideoDataOutput *)videoDataOutput{

    if(!_videoDataOutput) {

        _videoDataOutput = [[AVCaptureVideoDataOutput alloc] init];

        [_videoDataOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];

    }
    return _videoDataOutput;
}

// 添加监测环境光线变化的输出

    if ([self.captureSession canAddOutput:self.videoDataOutput]) {
       [self.captureSession addOutput:self.videoDataOutput];
   } 
#pragma mark -   代理AVCaptureVideoDataOutputSampleBufferDelegate - 
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {

    CFDictionaryRef metadataDict = CMCopyDictionaryOfAttachments(**NULL**, sampleBuffer, kCMAttachmentMode_ShouldPropagate);

    NSDictionary *metadata = [[NSMutableDictionary alloc] initWithDictionary:(__bridge NSDictionary*)metadataDict];

    CFRelease(metadataDict);

    NSDictionary *exifMetadata = [[metadata objectForKey:(NSString *)kCGImagePropertyExifDictionary] mutableCopy];

    float brightnessValue = [[exifMetadata objectForKey:(NSString *)kCGImagePropertyExifBrightnessValue] floatValue];

// #define brightnessThresholdValue (-0.2) //亮度阈值

    if (brightnessValue < brightnessThresholdValue) {

        dispatch_async(dispatch_get_main_queue(), ^{

            self.flashButton.hidden = NO;
            self.flashPremptLabel.hidden = NO;
        });
    }else{
        dispatch_async(dispatch_get_main_queue(), ^{

            self.flashButton.hidden = YES;
            self.flashPremptLabel.hidden = YES;
        });
    }
}

4.关于监听系统授权弹窗跳转的应用设置页

- (void)cameraLimitCheckToAlert{

    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if(authStatus == AVAuthorizationStatusNotDetermined) {
        // 申请权限
        [SRStatisticsManager permissionsS];
  [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
            dispatch_async(dispatch_get_main_queue(), ^{
                if(granted) {
                    self.flashButton.hidden = NO;
                    self.flashPremptLabel.hidden = NO;
                    [SRStatisticsManager permissionsC:@"OK"];
                }else{
                    [self showPermissionTipsAlert];
                    [SRStatisticsManager permissionsC:@"cancel"];
                }
           });
        }];
        return;
    }

     if(authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied) {
        //无权限 可以做一个友好的提示
         [self showPermissionTipsAlert];
         return;
     }
    if(authStatus == AVAuthorizationStatusAuthorized) {
        // 权限已获取
        self.flashButton.hidden = NO;
        self.flashPremptLabel.hidden = NO;
    }
}

5.App应用类评分阻塞线程问题

- (void)goToComment{

   NSUInteger count = [[[NSUserDefaults standardUserDefaults] objectForKey:@"appInCommentCount"] integerValue];
    count++;
   [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInteger:count] forKey:@"appInCommentCount"];

    // 获取当前版本号
    NSString *currentAppVersion =  [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];

    NSString *lastAppVersion  = [[NSUserDefaults standardUserDefaults] objectForKey:@"lastAppVersion"];
    if(![currentAppVersion isEqualToString:lastAppVersion] && count <= 3) {

        // 应用内评分
        if(@available(iOS 10.3, *)) {

            CGFloat twoSecondsFromNow = DISPATCH_TIME_NOW + 2.0;
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(twoSecondsFromNow * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

                dispatch_async(dispatch_get_main_queue(), ^{
                     [SKStoreReviewController requestReview];                 [[NSUserDefaults standardUserDefaults] setObject:currentAppVersion forKey:@"lastAppVersion"];
                });
            });

            return;
        }
    }

    NSURL *appUrl = [NSURL URLWithString:App_Write_Review_URL];
    if([[UIApplication sharedApplication] canOpenURL:appUrl]) {
        [[UIApplication sharedApplication] openURL:appUrl options:@{}completionHandler:nil];
    }

6.聊天第一次进入滚动到底部

 if(self.isScrollBottom) { //只在初始化的时候执行
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.005 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

          if(!SR_arrayIsEmpty(**self**.analyzeDataSources)) {
                NSIndexPath *indexPath = [NSIndexPath indexPathForRow:([self.palmistryAnalyzeTableViewnumberOfRowsInSection:0] - 1) inSection:0];           [self.palmistryAnalyzeTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottomanimated:NO];
            }
        });
    } 
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容