美文网首页
ios中遇到的问题

ios中遇到的问题

作者: 幽玄727 | 来源:发表于2021-05-24 15:38 被阅读0次

    1.ios中使用Callkit 来做来电弹屏功能

    1.对于数据量比较的大的,建议使用App Groups
    2.对于手机号码需要添加86
    3.对于固话需要加上86并去掉多余的符号(比如-)
    4.对于升级到ios14以后,手机号码来电弹屏有用,固话弹屏没用

    2.GPUImage美颜框架第一帧黑屏的问题

    在 GPUImageMovieWriter.m 中添加以下代码
    
    static BOOL allowWriteAudio =NO;
    
    - (void)startRecording;
    
    {
    
    allowWriteAudio=NO; // 添加这句
    
    }
    
    - (void)processAudioBuffer:(CMSampleBufferRef)audioBuffer;
    
    {
    
    if(!allowWriteAudio) {// 添加这个判断
    
    return;
    
    }
    
    
    }
    
    elseif(self.assetWriter.status==AVAssetWriterStatusWriting)
    
    {
    
    
    
    if(![assetWriterPixelBufferInputappendPixelBuffer:pixel_bufferwithPresentationTime:frameTime])
    
    NSLog(@"Problem appending pixel buffer at time: %@",CFBridgingRelease(CMTimeCopyDescription(kCFAllocatorDefault, frameTime)));
    
    allowWriteAudio=YES;// 添加这句
    
    }
    
    最后在你创建美颜相机方法后面加一句
    
    [_videoCamera addAudioInputsAndOutputs];
    
    

    如果以上方法不行,就对美颜后的视频进行处理,把视频第一帧删除

    3.启动图国际化处理

    创建多个LaunchScreen.storyboard文件,不同的语言针对不同的启动图

    image.png

    这里面有个问题,如果切换手机的系统语言,要想让启动图也跟着改变
    尝试使用方法1

    // 为了每次都读取最新的启动图,所以要在有缓存的时候清除缓,在APP启动以后调用改方法
    - (void)removeLaunchScreenCacheIfNeeded {
       NSString *filePath = [NSString stringWithFormat:@"%@/Library/SplashBoard", NSHomeDirectory()];
       
       if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
        NSError *error = nil;
        [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error];
    
        if (error) {
             NSLog(@"清除LaunchScreen缓存失败");
           } else {
             NSLog(@"清除LaunchScreen缓存成功");
           }
        }
    }
    

    此方法亲测没用,删除缓存中的启动图后,会导致,再次启动黑屏,苹果也不让修改Library/SplashBoard中的文件

    只有把APP删除,重新安装才能切换启动图的效果

    4.ios中使用BLE修改蓝牙设备的名称,但是名称缓存了

    在BLE规范中定义了缓存标准,参考蓝牙4.0规范vol3, Part G,2.5.2 Attribute Caching.这是为了优化,在客户端重新连接服务端时,可以重用上次发现的蓝牙服务信息。

    解决方法:
    方法一:在ios系统设置中,重新开启一次蓝牙开关,缓存就会被清除。

    方法二:等个一分钟左右在连接,缓存会自动清除

    方法三:当 APP 为中心连接其他的蓝牙设备时。

    首次连接成功过后,iOS系统内会将该外设缓存记录下来。

    下次重新搜索时,搜索到的蓝牙设备时,直接打印 (peripheral.name),得到的是之前缓存中的蓝牙名称。

    如果此期间蓝牙设备更新了名称,(peripheral.name)这个参数并不会改变,所以需要换一种方式获取设备的名称,在广播数据包内有一个字段为 kCBAdvDataLocalName,可以实时获取当前设备名称。

    //oc
    -(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *,id> *)advertisementData RSSI:(NSNumber *)RSSI{
           NSString *localName = [advertisementData objectForKey:@"kCBAdvDataLocalName"];
    }
    
    //Swift
    
    func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
           let localName = advertisementData["kCBAdvDataLocalName"]
    }
    

    但是此方法需要硬件做支持,有可能硬件没有在kCBAdvDataLocalName写入名称,导致kCBAdvDataLocalName返回的都是nil

    5.自定义framework引入宿主项目中冲突的问题

    在自定义framework中引入a.framework,然后在宿主项目中引入自定义framework和a.framework 有的项目会导致引入冲突,需要修改a.framework中类名相同的冲突

    但是我自定义尝试却没有冲突(很诧异),还在找原因 WechatIMG195.png

    6.淘宝客中商品详情的长图,如果不知道比例情况下的处理

    做商城项目的时候,商品详情的长图,如果自己平台,首先获取图片的比例在进行适配

    如果不知道会导致变形,就算根据内容适配也会造成每个图片布局混乱,
    在不知道图片比较的前提下,使用SDImageView把图片下载下来,获取比例在进行适配

    - (void)downloadImage:(NSString *)imageURL forIndexPath:(NSIndexPath *)indexPath {
        
     
        WS(weakSelf);
        // 利用 SDWebImage 框架提供的功能下载图片
        [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:imageURL] options:SDWebImageDownloaderUseNSURLCache progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
            
            
        } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
            
            [[SDImageCache sharedImageCache] storeImage:image forKey:imageURL completion:nil];
            //        [[SDImageCache sharedImageCache] storeImage:image forKey:imageURL toDisk:YES];
            
            
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf.footerTableView reloadData];
            });
        }];
        
        
    }
    

    注意:这种做法会导致内存警告⚠️
    所以需要在内存警告的时候,去清空缓存
    //当内存发生警告的时候 自动调用改方法-------清理缓存

    //AppDelegate中
    //当内存发生警告的时候 自动调用改方法-------清理缓存
    -(void)applicationDidReceiveMemoryWarning:(UIApplication *)application
    {
        [[SDImageCache sharedImageCache] clearDiskOnCompletion:nil];
    }
    
    //具体某个视图中
    //内存警告的时候,清理内存
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
        
        [[SDImageCache sharedImageCache] clearDiskOnCompletion:nil];
        
    }
    
    

    相关文章

      网友评论

          本文标题:ios中遇到的问题

          本文链接:https://www.haomeiwen.com/subject/hcdxsltx.html