美文网首页iOS随笔
iOS开发中的一些问题

iOS开发中的一些问题

作者: 095b62ead3cd | 来源:发表于2018-07-24 15:04 被阅读70次

    1、更新系统为High sierra 后无法使用Cocoapods:
    执行:

    sudo gem update --system
    sudo gem install -n /usr/local/bin cocoapods
    

    2、允许安装所有来源的APP命令行:

    sudo spctl --master-disable 
    

    3、Podfile文件变成exec格式使用命令行:

    chmod 644 + Podfile
    

    4、logo大小:

    58*58
    80*80
    87*87
    120*120
    180*180
    1024*1024
    

    启动页:

    640*1136
    750*1334
    1242*2208
    

    (png格式)
    5、常见机型尺寸:

    iPhone5:640*1136
    iPhone6:750*1334
    iPhone 7 Plus:1080*1920
    iPhone X:2436*1125
    

    6、使用Masonry布局后出现类似以下的警告:

    Probably at least one of the constraints in the following list is one you don't want. 
        Try this: 
            (1) look at each constraint and try to figure out which you don't expect; 
            (2) find the code that added the unwanted constraint or constraints and fix it. 
    (
        <MASLayoutConstraint:0x6180000ae280 UIImageView:0x7faae702cc50.left == XBMixButton:0x7faae702c830.left>,
        <MASLayoutConstraint:0x6180000ae3a0 UIImageView:0x7faae702cc50.width == XBMixButton:0x7faae702c830.height>,
        <MASLayoutConstraint:0x6180000b2360 XBMixButton:0x7faae702de30.width == 80>,
        <MASLayoutConstraint:0x6180000b23c0 XBMixButton:0x7faae702de30.height == 15>,
        <MASLayoutConstraint:0x6000000ab760 XBMixButton:0x7faae702c830.width == XBMixButton:0x7faae702de30.width>,
        <MASLayoutConstraint:0x6000000abfa0 XBMixButton:0x7faae702c830.height == XBMixButton:0x7faae702de30.height>,
        <NSLayoutConstraint:0x61800008f550 UIImageView:0x7faae702cc50.centerX == XBMixButton:0x7faae702c830.centerX>,
    )
    Will attempt to recover by breaking constraint 
    <NSLayoutConstraint:0x61800008f550 UIImageView:0x7faae702cc50.centerX == XBMixButton:0x7faae702c830.centerX>
    

    解决办法有两种:
    1.找到该控件,修改它的相关约束,以消除警告信息。
    2.将控件的约束优先级置为高级,那么就算约束重复了也不会有警告。这也是最简单省事的办法。
    如下:

    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(ws).offset(SPACE).priorityHigh();
                make.top.mas_equalTo(ws).offset(SPACE).priorityHigh();
                make.bottom.mas_equalTo(ws).offset(-SPACE).priorityHigh();
                make.width.mas_equalTo(ws.mas_height).priorityHigh();
    ];
    

    (此处引用其他人代码,这个比较详细,我的跟这个类似就不贴了)

    7、写了个遮罩弹窗,在使用Masonry的时候,布局写的没问题,但是界面出现错误,我的解决办法是在弹窗移除后,将里面的控件置为nil,这样下次弹窗的时候就没问题了。

    8、上传App Store时突然出现“No account with iTunes Connect access have been found for the team "".iTunes Connect access is……”
    解决办法:

    1、关闭Xcode 
    2、终端命令:rm -fr ~/Library/Developer/Xcode/DerivedData/ 
    3、重启Xcode,然后再重新上传App Store
    

    9、调试问题代码:

    @try {
                //问题代码
                
                
            }
            
            @catch (NSException *exception) {
                NSLog(@"exception = %@", exception);
            }
            
            @finally {
                
            }
    

    10、weak的作用及底层原理:

    weak 关键字的作用弱引用,所引用对象的计数器不会加一,并在引用对象被释放的时候自动被设置为 nil。
    底层原理:weak是Runtime维护了一个hash(哈希)表,用于存储指向某个对象的所有weak指针。weak表其实是一个hash(哈希)表,Key是所指对象的地址,Value是weak指针的地址(这个地址的值是所指对象指针的地址)数组。
    

    11、Xcode10 打开旧项目报错Multiple commands produce定位到Info.plist解决方案
    问题描述:升级了xcode10后,打开项目会报以下错误:

    Showing All Messages
    
    Prepare build
    note: Using new build systemnote: Planning buildnote: Constructing build description
    
    Build system information
    warning: The iOS Simulator deployment target is set to 6.0, but the range of supported deployment target versions for this platform is 8.0 to 12.1. (in target 'Aspects')
    Build system information
    warning: The iOS Simulator deployment target is set to 4.3, but the range of supported deployment target versions for this platform is 8.0 to 12.1. (in target 'FMDB')
    Build system information
    warning: The iOS Simulator deployment target is set to 7.0, but the range of supported deployment target versions for this platform is 8.0 to 12.1. (in target 'AFNetworking')
    Build system information
    warning: The iOS Simulator deployment target is set to 6.0, but the range of supported deployment target versions for this platform is 8.0 to 12.1. (in target 'MJExtension')
    Build system information
    warning: The iOS Simulator deployment target is set to 6.0, but the range of supported deployment target versions for this platform is 8.0 to 12.1. (in target 'Masonry')
    Build system information
    warning: The iOS Simulator deployment target is set to 6.0, but the range of supported deployment target versions for this platform is 8.0 to 12.1. (in target 'MJRefresh')
    Build system information
    warning: The Copy Bundle Resources build phase contains this target's Info.plist file '/Users/imac03/Desktop/iOSAllCode/OA-Code/OCT-OA/OCT-OA/Info.plist'. (in target 'OCT-OA')
    Build system information
    warning: duplicate output file '/Users/imac03/Library/Developer/Xcode/DerivedData/OCT-OA-cwjbwvcshyvwcsfovmgijeevazfj/Build/Products/Debug-iphonesimulator/OCT-OA.app/Info.plist' on task: ProcessInfoPlistFile /Users/imac03/Library/Developer/Xcode/DerivedData/OCT-OA-cwjbwvcshyvwcsfovmgijeevazfj/Build/Products/Debug-iphonesimulator/OCT-OA.app/Info.plist /Users/imac03/Desktop/iOSAllCode/OA-Code/OCT-OA/OCT-OA/Info.plist (in target 'OCT-OA')
    Build system information
    error: Multiple commands produce '/Users/imac03/Library/Developer/Xcode/DerivedData/OCT-OA-cwjbwvcshyvwcsfovmgijeevazfj/Build/Products/Debug-iphonesimulator/OCT-OA.app/Info.plist':
    1) Target 'OCT-OA' (project 'OCT-OA') has copy command from '/Users/imac03/Desktop/iOSAllCode/OA-Code/OCT-OA/OCT-OA/Info.plist' to '/Users/imac03/Library/Developer/Xcode/DerivedData/OCT-OA-cwjbwvcshyvwcsfovmgijeevazfj/Build/Products/Debug-iphonesimulator/OCT-OA.app/Info.plist'
    2) Target 'OCT-OA' (project 'OCT-OA') has process command with output '/Users/imac03/Library/Developer/Xcode/DerivedData/OCT-OA-cwjbwvcshyvwcsfovmgijeevazfj/Build/Products/Debug-iphonesimulator/OCT-OA.app/Info.plist'
    
    
    Build target Aspects of project Pods with configuration Debug
    
    CreateBuildDirectory /Users/imac03/Library/Developer/Xcode/DerivedData/OCT-OA-cwjbwvcshyvwcsfovmgijeevazfj/Build/Intermediates.noindex (in target: Aspects)
        cd /Users/imac03/Desktop/iOSAllCode/OA-Code/OCT-OA/Pods
        builtin-create-build-directory /Users/imac03/Library/Developer/Xcode/DerivedData/OCT-OA-cwjbwvcshyvwcsfovmgijeevazfj/Build/Intermediates.noindex
    
    CreateBuildDirectory /Users/imac03/Library/Developer/Xcode/DerivedData/OCT-OA-cwjbwvcshyvwcsfovmgijeevazfj/Build/Products (in target: Aspects)
        cd /Users/imac03/Desktop/iOSAllCode/OA-Code/OCT-OA/Pods
        builtin-create-build-directory /Users/imac03/Library/Developer/Xcode/DerivedData/OCT-OA-cwjbwvcshyvwcsfovmgijeevazfj/Build/Products
    
    
    
    Build failed    2018/12/25 下午2:29    1.5 seconds
    

    解决方案:
    xcode-->file-->workspace setting-->build system(改成Legacy Build System)-->done


    图示1 图示2

    编译后,通过。

    问题原因:

    Xcode10新增了一个构建系统起名“New Build System”(新构建系统),在Xcode10正式发布会变成了Xcode的默认Build System,旧的构建系统称为 legacy build system (传统构建系统)。
    

    12、在线移动图标生成工具:图标工场http://icon.wuruihong.com/网站自动生成iOS所需的所有对应格式的图标

    13、跳转到APP Store中该APP的下载页面(XXXXXX替换成你自己APP的 appid ):

    https://itunes.apple.com/cn/app/qq/idXXXXXXXX?mt=8
    

    14、json字符串转NSDictionry

    + (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
        if (jsonString == nil) {
            return nil;
        }
        NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
        NSError *err;
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
    
                                                            options:NSJSONReadingMutableContainers
    
                                                              error:&err];
        if(err) {
            NSLog(@"json解析失败:%@",err);
            return nil;
        }
        return dic;
    }
    

    15、iOS单例写法的优化

    + (instancetype)shareInstance{
        static TShareManager *manager = nil;
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            manager = [[TShareManager alloc] init];
        });
        return manager;
    }
    

    但这种写法在用alloc init或者new初始化对象的时候会重新开辟空间,这样就造成了这个对象不是全局的唯一实例。在用alloc init或者new初始化对象的时候会调用allocWithZone方法,所以我们只需要重写allocWithZone方法,就可以解决这个问题。

    + (instancetype)allocWithZone:(struct _NSZone *)zone{
        static TShareManager *manager = nil;
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            manager = [super allocWithZone:zone];
        });
        return manager;
    }
    

    (待续)

    相关文章

      网友评论

        本文标题:iOS开发中的一些问题

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