iOS_tips

26、xcode16, pod install 后編譯報錯:

Sandbox: rsync(11366) deny(1) file-read-data /Users/liucl/Library/Developer/Xcode/DerivedData/demo-dohbrcttlkngnkgzbrjxclpoakgk/Build/Products/Debug-iphonesimulator/demo.app/Frameworks/Masonry.framework/_CodeSignature

參考鏈接

檢查ENABLE_USER_SCRIPT_SANDBOXING項目的構(gòu)建設(shè)置中是否已禁用。

25、UICollectionView卡片拖拽管理
參考鏈接

// iOS9以上寫法
// 手勢監(jiān)聽
    private func _setupLongGesture() {
        
        let longGes = UILongPressGestureRecognizer.init(target: self, action: #selector(longPressAction(_:)))
        cvTop.addGestureRecognizer(longGes)
    }
    
    @objc private func longPressAction(_ sender: UILongPressGestureRecognizer) {
      
        switch sender.state {
            
        case .began:
            let path = cvTop.indexPathForItem(at: sender.location(in: cvTop))
            if path == nil {
                break
            }
            let cell = cvTop.cellForItem(at: path!)
            self.view.bringSubviewToFront(cell!)
            cvTop.beginInteractiveMovementForItem(at: path!)
            
            break
        case .changed:
            cvTop.updateInteractiveMovementTargetPosition(sender.location(in: cvTop))
            break
        case .ended:
            cvTop.endInteractiveMovement()
            break
        case .possible, .cancelled, .failed:
            cvTop.cancelInteractiveMovement()
        @unknown default:
            cvTop.cancelInteractiveMovement()
            break
        }
    }

24、UILabel固定高度時,文字垂直居中改為頂部對齊參考鏈接

/// UILabel固定高度時,文字從垂直居中改為頂部對齊
class BMTopicLabel: UILabel {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    override func textRect(forBounds bounds: CGRect, limitedToNumberOfLines numberOfLines: Int) -> CGRect {
        var rect = super.textRect(forBounds: bounds, limitedToNumberOfLines: numberOfLines)
        rect.origin.y = bounds.origin.y
        return rect
    }
    
    override func drawText(in rect: CGRect) {
        let rect = textRect(forBounds: rect, limitedToNumberOfLines: numberOfLines)
        super.drawText(in: rect)
    }
}

// 移動邏輯

    func collectionView(_ collectionView: UICollectionView, canMoveItemAt indexPath: IndexPath) -> Bool {
        if collectionView == cvTop {
            return true
        }
        return false
    }
    
    func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
        let m = group0[sourceIndexPath.item]
        group0.remove(at: sourceIndexPath.item)
        group0.insert(m, at: destinationIndexPath.item)
        
        // 移動結(jié)束后刷新
        var arr: [BMWristBandCardModel] = []
        arr.append(contentsOf: group0)
        arr.append(contentsOf: group1)
        BMDeviceTool.bm_saveCardList(arr: arr)
        
        if cardEditCloser != nil {
            cardEditCloser!()
        }
    }

23、Xcode15.3打包,Handyjson報錯Call parameter type does not match function signature!
解決辦法:Xcode 15.3 Archive失敗
參考鏈接

// 在 Pods-Target-HandyJSON-build settings。
// 然后設(shè)置Optimization Level為
// None和No Optimization。

升級Xcode15后 打包報錯 xxx Command SwiftCompile failed with a nonzero exit code

解決辦法: 選中pod 報錯的庫 Code Generation->Compilation Mode改成和debug一樣的 Incremental。
22、打包提交審核報錯opencv2, PaddleLite
1、pod ‘OpenCV2’ 默認版本 V4.3.0
2、刪除項目源文件opencv2
3、編譯報錯
'opencv2/highgui/cap_ios.h' file not found ->改為 #import <opencv2/videoio/cap_ios.h>

https://blog.csdn.net/Story51314/article/details/54617451/

opencv2/highgui/ios.h' file not found -> 改為 #include <opencv2/imgcodecs/ios.h>

'opencv2\imgproc\types_c.h' file not found 改為 #include <opencv2/core/types_c.h>

Use of undeclared identifier 'CV_BGR2RGB' 頭文件導(dǎo)入 #include <opencv2/imgproc/types_c.h>

4、頭文件引入注意事項

其中 一個警告 Detected Apple 'NO' macro definition, it can cause build conflicts. Please, include this header before any Apple headers.

意思是 讓我們在引用這個頭文件的時候應(yīng)該放在所有Apple頭文件之前

鏈接:http://www.itdecent.cn/p/ff1a035df84f

5、參考4,調(diào)整各個文件目錄順序

6、刪除libjpeg.a文件,pod集成DFJPEGTurbo

7、文件結(jié)構(gòu)報錯

Invalid bundle structure. The “ShowMe.app/third-party/PaddleLite/lib/libpaddle_api_light_bundled.a” binary file is not permitted. Your app cannot contain standalone executables or libraries, other than a valid CFBundleExecutable of supported bundles.

刪除

鏈接:https://blog.csdn.net/wsyx768/article/details/129073522

21、iOS截圖長圖代碼實現(xiàn)

+ (UIImage *)cz_longFigureForScrollView:(UIScrollView *)scrollView;
+ (UIImage *)cz_longFigureForScrollView:(UIScrollView *)scrollView {
    UIImage* image = nil;
    UIGraphicsBeginImageContextWithOptions(scrollView.contentSize, YES, 0.0);
    
    //保存collectionView當前的偏移量
    CGPoint savedContentOffset = scrollView.contentOffset;
    CGRect saveFrame = scrollView.frame;
    
    //將collectionView的偏移量設(shè)置為(0,0)
    scrollView.contentOffset = CGPointZero;
    scrollView.layer.frame = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);
    
    //在當前上下文中渲染出collectionView
    [scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];
    //截取當前上下文生成Image
    image = UIGraphicsGetImageFromCurrentImageContext();
    
    //恢復(fù)collectionView的偏移量
    scrollView.contentOffset = savedContentOffset;
    scrollView.layer.frame = saveFrame;
    
    UIGraphicsEndImageContext();
    
    if (image != nil) {
        return image;
    }else {
        return nil;
    }
}

20、審核中可能被懷疑的問題

1.1.6 - Include false information, features, or misleading metadata.
2.3.0 - Undergo significant concept changes after approval
2.3.1 - Have hidden or undocumented features, including hidden "switches" that redirect to a gambling or lottery website
3.1.1 - Use payment mechanisms other than in-app purchase to unlock features or functionality in the app
3.2.1 - Do not come from the financial institution performing the loan services
4.3.0 - Are a duplicate of another app or are conspicuously similar to another app
5.2.1 - Were not submitted by the legal entity that owns and is responsible for offering any services provided by the app
5.2.3 - Facilitate illegal file sharing or include the ability to save, convert, or download media from third party sources without explicit authorization from those sources
5.3.4 - Do not have the necessary licensing and permissions for all the locations where the app is used

19、注冊錯誤,不允許注冊時要求用戶填寫身份證+姓名等敏感信息。


registererror.png

18、IPV6審核失敗解決方案


ipv6error.png
// app在國內(nèi)環(huán)境登錄使用一切正常,審核人員登錄時會提示連接失敗,報500錯誤!并且期初錯誤無法復(fù)現(xiàn)。
// 錯誤復(fù)現(xiàn)場景,在手機設(shè)置->通用->地區(qū)與時間->將國家改為美國,成功復(fù)現(xiàn)連接失敗錯誤!
// 配合后臺同事調(diào)試,發(fā)現(xiàn)為語言包配置錯誤導(dǎo)致連接失敗,沒有返回任何內(nèi)容。

17、IPV6審核失敗解決方案
App Store ipv6 審核一直被拒絕
錯誤: iOS審核被拒之 ipv6
阿里云 Ubuntu 支持 IPv6 的完整步驟

16、SDWebImage在4.0之后不再支持加載gif動圖,需要單獨導(dǎo)入支持gif的庫即可。

pod 'SDWebImage/GIF'
// 使用FLAnimatedImageView來代替UIImageView即可加載Gif圖片

15、測試安裝app時報錯“This application does not support this device’s CPU type.”

// 原因:32位的Application已經(jīng)被蘋果淘汰,不再支持安裝!
// 解決:項目中找到 Build Settings -> Architectures ,修改為 standard architectures 即可!

14、如何在用戶退出時清空單例對象值,并且保證在重新登錄時可以新建單例對象?
iOS 單列的創(chuàng)建和銷毀

+ (void)qmx_userDealloc {
    onceToken = 0;
    _instance = nil;
}

// 1. 必須把static dispatch_once_t onceToken; 這個拿到函數(shù)體外,成為全局的. 
// 2.只有置成0,GCD才會認為它從未執(zhí)行過.它默認為0.這樣才能保證下次再次調(diào)用shareInstance的時候,再次創(chuàng)建對象.

13、UICollectionView用法補充

// MARK: - 1.header注冊方式
// 參數(shù)2 在頭文件最頂部 header 或 footer
[cv registerClass:[ZXFPhotoAlbumHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerID];
// MARK: - 2.顯示header
// 需要在布局屬性中設(shè)置header的size
self.headerReferenceSize = CGSizeMake(self.collectionView.width, 40);
// MARK: - 3.其他
// header類型是繼承自 UICollectionReusableView
// 返回視圖的方法
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    
    ZXFPhotoAlbumHeaderView *headerV = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerID forIndexPath:indexPath];
    
    headerV.title = [NSString stringWithFormat:@"這是第 %@ 組", @(indexPath.section).description];
    
    return headerV;
}

12.iOS Crash文件分析
iOS Crash - 分析篇

11.UITextField文本框的光標處理

// 會影響所有光標顏色
[[UITextField appearance] setTintColor:[UIColor blackColor]];
// 單獨修改某一個光標顏色
textField.tintColor = [UIColor redColor]; 
// 不顯示光標
textField.tintColor = [UIColor clearColor]; 

10.控件超出父控件范圍無法響應(yīng)的問題

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    
    //1. 邊界情況:不能響應(yīng)點擊事件
    BOOL canNotResponseEvent = self.hidden || (self.alpha <= 0.01f) || (self.userInteractionEnabled == NO);
    if (canNotResponseEvent) {
        return nil;
    }
    
    //2. 最后處理 TabBarItems 凸出的部分、添加到 TabBar 上的自定義視圖、點擊到 TabBar 上的空白區(qū)域
    UIView *result = [super hitTest:point withEvent:event];
    if (result) {
        return result;
    }
    
    for (UIView *subview in self.subviews.reverseObjectEnumerator) {
        CGPoint subPoint = [subview convertPoint:point fromView:self];
        result = [subview hitTest:subPoint withEvent:event];
        if (result) {
            return result;
        }
    }
    return nil;
}

9.WebView問題

問題:使用UIWebView加載鏈接時,底部總是出現(xiàn)黑色的橫條。
解決:設(shè)置webView的opaque屬性為NO,背景顏色設(shè)置clearColor即可。

8.友盟分享集成問題

集成選擇了微信、QQ、新浪微博。
問題:在彈出的分享面板中微信始終不能出現(xiàn)。
解決:將完整的微信SDK,切換為精簡版的微信分享SDK,界面正常展示

7.字體加粗及傾斜
ios 字體類型設(shè)置 傾斜加粗等

字體加粗
loginLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
字體加粗并且傾斜
loginLabel.font = [UIFont fontWithName:@"Helvetica-BoldOblique" size:20];

6.調(diào)整文字間距和行距
iOS開發(fā)小知識之改變UIlabel的行間距和字間距

#import <UIKit/UIKit.h>

@interface UILabel (ChangeLineSpaceAndWordSpace)

/**
 *  改變行間距
 */
+ (void)changeLineSpaceForLabel:(UILabel *)label WithSpace:(float)space;

/**
 *  改變字間距
 */
+ (void)changeWordSpaceForLabel:(UILabel *)label WithSpace:(float)space;

/**
 *  改變行間距和字間距
 */
+ (void)changeSpaceForLabel:(UILabel *)label withLineSpace:(float)lineSpace WordSpace:(float)wordSpace;

@end
#import "UILabel+ChangeLineSpaceAndWordSpace.h"

@implementation UILabel (ChangeLineSpaceAndWordSpace)

+ (void)changeLineSpaceForLabel:(UILabel *)label WithSpace:(float)space {

    NSString *labelText = label.text;
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:space];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];
    label.attributedText = attributedString;
    [label sizeToFit];

}

+ (void)changeWordSpaceForLabel:(UILabel *)label WithSpace:(float)space {

    NSString *labelText = label.text;
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText attributes:@{NSKernAttributeName:@(space)}];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];
    label.attributedText = attributedString;
    [label sizeToFit];

}

+ (void)changeSpaceForLabel:(UILabel *)label withLineSpace:(float)lineSpace WordSpace:(float)wordSpace {

    NSString *labelText = label.text;
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText attributes:@{NSKernAttributeName:@(wordSpace)}];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:lineSpace];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];
    label.attributedText = attributedString;
    [label sizeToFit];

}

@end

1.cornerstone上傳默認忽略.a庫文件,導(dǎo)致項目編譯報錯!

  解決:設(shè)置cornerstone的偏好設(shè)置,不要忽略.a庫文件即可!
cornerstone ->preferences->Subversion->關(guān)閉 Use default global ignores -> 刪除 *a選項!
cornerstone.png

2.環(huán)信推送測試收不到推送消息
【原來配置環(huán)信apns就這么簡單】內(nèi)含各種問題點詳講

  -> 1.測試證書的軟件 Ease APNs Provider 可以測試生成的cer推送證書是否有問題
  -> 2.按照文檔進行排查 
  
錯誤:上傳的測試證書,環(huán)境選擇成了開發(fā)環(huán)境!
解決:重新上傳證書,正確選擇環(huán)境即可

3.UISlider控件觸發(fā)值改變事件比較頻繁!

UISlider *slider = [[UISlider alloc] init];
UIImage *img = [UIImage imageNamed:@"fontchange"];
// 只在手指抬起時觸發(fā)一次值改變事件
slider.continuous = NO;
[slider setThumbImage:img forState:UIControlStateNormal];

4.”A valid provisioning profile for this executable was not found“

從描述上可以看到說:對于可執(zhí)行provisioning profile 沒有被找到。所以網(wǎng)上有很多答案是說你provisioning profile沒有被找到,需要重新導(dǎo)入之類的。
 http://blog.sina.com.cn/s/blog_71715bf8010164z5.html
但是我碰到的原因是我在Project中將Code Signing Identity中將其設(shè)置成了iPhone Develop,但是在Target中的Code Signing Identity并沒有自動切換過來,我發(fā)現(xiàn)在Target中的Code Signing Identity還是我之前的設(shè)的iPhone Distribution,
所以看到這里就知道了,iPhone Distribution 的provisioning profile肯定是不能運行的,所以把Target中的Code Signing Identity也設(shè)置成iPhone Develop就ok了,這樣一切都說的通了,唯一不合理的就是在Project切換Code Signing Identity并編譯,但xCode沒有自動將編譯后的Target設(shè)置成和Project中的一致

5.上傳錯誤
提交審核之前,如果需要更新構(gòu)建版本,只需要更新CFBundleVersion就可以,不需要更改版本號!


屏幕快照 2017-04-28 上午9.35.38.png
解決了第一個錯誤就沒問題了,原因是環(huán)信SDK中支持了X86_64
http://docs.easemob.com/im/300iosclientintegration/20iossdkimport
屏幕快照 2017-04-28 上午10.07.36.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容