iOS開發(fā)筆記《持續(xù)更新》

有遇到Apple賬號申請問題,App上傳Appstore問題,iTunes Connect相關(guān)問題,都可以根據(jù)您所在地區(qū)撥打相應(yīng)的電話進(jìn)行咨詢,我以前打過【China English, 普通話 Mon-Fri, 09:00-17:00 CST 4006 701 855】:點擊查看電話列表

1、生成隨機數(shù)

int x = arc4random() % 9;生成以為隨機數(shù)
生成6位隨機數(shù)

    NSString *strRandom = @"";
    
    for(int i=0; i<7; i++)
    {
        strRandom = [strRandom stringByAppendingFormat:@"%i",(arc4random() % 9)];
    }
    NSLog(@"隨機數(shù): %@", strRandom);

2、判斷App是否第一次啟動

    if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstStart"]){
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstStart"];
        NSLog(@"第一次啟動");
    }else{
        NSLog(@"不是第一次啟動");
    }

3、UIView中的initWithFrame 和 initWithCoder

當(dāng)我們所寫的程序里沒用用Nib文件(XIB)時,用代碼控制視圖內(nèi)容,需要調(diào)用initWithFrame去初始化

- (id)initWithFrame:(CGRect)frame
{
    if (self =[super initWithFrame:frame]) {
        // 初始化代碼
    }
    return self;
}

用于視圖加載nib文件,從nib中加載對象實例時,使用 initWithCoder初始化這些實例對象

- (id)initWithCoder:(NSCoder*)coder
{
    if (self =[super initWithcoder:coder]) {
        // 初始化代碼
    }
    return self;
}

4、一個Lable有多種顏色類似這樣:

實例.png
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"恭喜130****8565 于04月02日獲得iPhone6s"];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor darkGrayColor] range:NSMakeRange(0,1)];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(2,12)];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(15,5)];
    UILabel *attrLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 64, 320 - 40, 90)];
    attrLabel.attributedText = str;
    attrLabel.numberOfLines = 0;
    [self.view addSubview:attrLabel];

5、獲取當(dāng)前時間的年月日時分秒

6、
調(diào)用代碼使APP進(jìn)入后臺
帶中文的URL處理
取WebView高度
View設(shè)置圖片
去TableView分割線
調(diào)cell分割線位置
七、Label注意事項
搜索條Cancel改標(biāo)題
TableView收鍵盤
NSTimer
控制器沒大小
十六進(jìn)制取顏色
獲取今天是星期幾
UIView的部分圓角問題
滑動時隱藏navigationBar
iOS畫虛線
自動布局多行UILabel問題
禁止運行時自動鎖屏
KVC相關(guān)
用MBProgressHud問題
強制App直接退出
Label行間距
pod更新慢的問題
MRC和ARC混編設(shè)置方式
cell對勾顏色修改
同時按兩個按鈕問題
修改占位符顏色和大小
禁止復(fù)制粘貼
進(jìn)入App在AppStore頁面
隱藏系統(tǒng)tabbar
取消系統(tǒng)的返回手勢
改WebView字體/顏色

7、 運行錯誤信息No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=armv7

運行報錯出現(xiàn)的原因:armv7s是應(yīng)用在iPhone 5 A6 的架構(gòu)上的解決的方式:
1、在Project target里“Architectures”設(shè)置為“Standard (armv7,armv7s)”
2、修改在Project target里“Build Settings”的“Valid Architectures”添加“i386”和“armv7”(Xcode4.6 以上版本不再支持armv6,請去掉)
3、設(shè)置”Build Active Architecture Only”為“NO”。這樣你build你的項目的時候就能在iphoe5和iphoe4s里執(zhí)行。armv6, armv7, armv7s的區(qū)別

8、Mac 刷新DNS命令:

10.10.4 or later:
sudo killall -HUP mDNSResponder

10.10 ~ 10.10.3:
sudo discoveryutil mdnsflushcache

10.7 ~ 10.9.5:
sudo killall -HUP mDNSResponder

10.6 ~ 10.6.8:
sudo dscacheutil -flushcache

9、NSData和NSDictionary轉(zhuǎn)換

獲得的json先轉(zhuǎn)換成字符串
NSString *receiveStr = [[NSString alloc]initWithData:receiveData encoding:NSUTF8StringEncoding];
字符串再生成
NSDataNSData * data = [receiveStr dataUsingEncoding:NSUTF8StringEncoding]; 
再解析  
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
就OK了 

10、
iOS10相關(guān)問題記錄:
iOS10相冊相機閃退bug
iOS 10 因蘋果健康導(dǎo)致閃退 crash
麥克風(fēng)、多媒體、地圖、通訊錄
ios10相機等崩潰

iOS10 配置須知
iOS開發(fā) 適配iOS10以及Xcode8
iOS 10 的適配問題

iOS對用戶的安全和隱私的增強,在申請很多私有權(quán)限的時候都需要添加描述,但是,在使用Xcode 8之前的Xcode還是使用系統(tǒng)的權(quán)限通知框.
要想解決這個問題,只需要在info.plist添加NSContactsUsageDescription的key, value自己隨意填寫就可以,這里列舉出對應(yīng)的key(Source Code模式下):

iOS11以前: 
NSPhotoLibraryUsageDescription:訪問相冊和存儲照片到相冊(讀寫),會出現(xiàn)用戶授權(quán)。 
iOS11之后: 
NSPhotoLibraryUsageDescription:無需添加。默認(rèn)開啟訪問相冊權(quán)限(讀),無需用戶授權(quán)。 
NSPhotoLibraryAddUsageDescription: 添加內(nèi)容到相冊(寫),會出現(xiàn)用戶授權(quán)。 

<!-- 相冊 --> 
<key>NSPhotoLibraryUsageDescription</key> 
<string>App需要您的同意,才能訪問相冊</string> 
<!-- 相機 --> 
<key>NSCameraUsageDescription</key> 
<string>App需要您的同意,才能訪問相機</string> 
<!-- 麥克風(fēng) --> 
<key>NSMicrophoneUsageDescription</key> 
<string>App需要您的同意,才能訪問麥克風(fēng)</string> 
<!-- 位置 --> 
<key>NSLocationUsageDescription</key> 
<string>App需要您的同意,才能訪問位置</string> 
<!-- 在使用期間訪問位置 --> 
<key>NSLocationWhenInUseUsageDescription</key> 
<string>App需要您的同意,才能在使用期間訪問位置</string> 
<!-- 始終訪問位置 --> 
<key>NSLocationAlwaysUsageDescription</key> 
<string>App需要您的同意,才能始終訪問位置</string> 
<!-- 日歷 --> 
<key>NSCalendarsUsageDescription</key> 
<string>App需要您的同意,才能訪問日歷</string> 
<!-- 提醒事項 --> 
<key>NSRemindersUsageDescription</key> 
<string>App需要您的同意,才能訪問提醒事項</string> 
<!-- 運動與健身 --> 
<key>NSMotionUsageDescription</key> <string>App需要您的同意,才能訪問運動與健身</string> 
<!-- 健康更新 --> 
<key>NSHealthUpdateUsageDescription</key> 
<string>App需要您的同意,才能訪問健康更新 </string> 
<!-- 健康分享 --> 
<key>NSHealthShareUsageDescription</key> 
<string>App需要您的同意,才能訪問健康分享</string> 
<!-- 藍(lán)牙 --> 
<key>NSBluetoothPeripheralUsageDescription</key> 
<string>App需要您的同意,才能訪問藍(lán)牙</string> 
<!-- 媒體資料庫 --> 
<key>NSAppleMusicUsageDescription</key> 
<string>App需要您的同意,才能訪問媒體資料庫</string>

11、tableView在編輯狀態(tài)下的批量操作(多選)
注意:
** cell的selectionStyle不要設(shè)置為UITableViewSelectionStyleNone**

12、設(shè)置圓角:layer.cornerRadius

設(shè)置圓角.png

13、 解決iOS The document “(null)” requires Xcode 8.0 or later. 不能編譯的問題:

用文本編輯器打開對應(yīng)的  xib 文件,刪除其中類似這樣的一句話  <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>

14、 iOS中判斷是從哪個控制器push進(jìn)來的,返回指定控制器:

1、
push將控制器壓到棧中,棧是先進(jìn)后出;pop是出棧:即將控制器從棧中取出。
 NSArray*arrController =self.navigationController.viewControllers;
 NSInteger VcCount = arrController.count;
 //最后一個vc是自己,(-2)是倒數(shù)第二個是上一個控制器。
 UIViewController *lastVC = arrController[VcCount - 3];
// 返回到倒數(shù)第三個控制器
 if ([lastVC isKindOfClass:[XZViewController class]]) {
   [self.navigationController popToViewController:lastVC animated:YES];
}
2、
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
3、
返回到指定的控制器:遍歷一遍子控制器,判斷一下哪個是要返回的控制器,進(jìn)行返回
for (UIViewController *controller in self.navigationController.viewControllers) {

        if ([controller isKindOfClass:[XZViewController class]]) {

            [self.navigationController popToViewController:controller animated:YES];

        }

 }

15、關(guān)于iOS去除數(shù)組中重復(fù)數(shù)據(jù)的幾種方法:連接

16、iOS9 適配(https適配信息):

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>

17、Xcode 遇到這個問題**Installation Failed Invalid argument **

Installation Failed Invalid argument.png

解決方法:

Quit Xcode
Clean out ~/Library/Developer/Xcode/DerivedData manually
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
iOS Simulator > Reset Content and Settings

18、 iOS 獲取Wifi的SSID及MAC地址

導(dǎo)入系統(tǒng)頭文件
 #import <SystemConfiguration/CaptiveNetwork.h>
實現(xiàn)代碼
NSString *ssid = @"Not Found";
    NSString *macIp = @"Not Found";
    CFArrayRef myArray = CNCopySupportedInterfaces();
    if (myArray != nil) {
        CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
        if (myDict != nil) {
            NSDictionary *dict = (NSDictionary*)CFBridgingRelease(myDict);
            
            ssid = [dict valueForKey:@"SSID"];
            macIp = [dict valueForKey:@"BSSID"];
        }
    }
    UIAlertView *av = [[UIAlertView alloc] initWithTitle:ssid
                                                 message:macIp
                                                delegate:nil
                                       cancelButtonTitle:nil
                                       otherButtonTitles:@"OK", nil];
    [av show];

19、iOS 獲取當(dāng)前設(shè)備型號iPhone7/iPhone7P

20、解決10.12安全與隱私?jīng)]有允許任何來源的選項
在終端里輸入:sudo spctl --master-disable 然后回車即可在安全選項中看到重新出現(xiàn)的允許任何來源選項!

21、真機調(diào)試:Development cannot be enabled while your device is locked.
解決方法:打開手機設(shè)置->通用->還原->還原位置與隱私;
拔掉數(shù)據(jù)線,重啟xocde 8開啟項目, 重新插上數(shù)據(jù)線,此時手機上會顯示mac與手機設(shè)備的連接訪問權(quán)限,選擇“信任”,

22、iOS不支持64系統(tǒng)報錯的解決方法:
錯誤No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=armv7, VA

Paste_Image.png

解決方法:
運行報錯出現(xiàn)的原因:armv7s是應(yīng)用在iPhone 5 A6 的架構(gòu)上的解決的方式:

1,在Project target里“Architectures”設(shè)置為“Standard (armv7,armv7s)”
2,修改在Project target里“Build Settings”的“Valid Architectures”添加“i386”和“armv7”(Xcode4.6 以上版本不再支持armv6,請去掉)
3,設(shè)置”Build Active Architecture Only”為“NO”。這樣你build你的項目的時候就能在iphoe5和iphoe4s里執(zhí)行。armv6, armv7, armv7s的區(qū)別

No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=i386)

23 如果你的項目莫名奇妙的出現(xiàn)

: Linker command failed with exit code 1 (use -v to see invocation)

Paste_Image.png

解決:好吧我不知道為啥Xcode8之后就沒法看詳情了。但是可能是BitCode搞得鬼


自記:用callkit的時候,記入帶區(qū)號的號碼時格式如010 ->10不要帶0

24 Signing for "" requires a development team. Select a developm

http://stackoverflow.com/questions/43334982/trying-to-build-to-tablet-wanted-dev-team-profile-added-one-but-now-failing-f

25 真機調(diào)試出現(xiàn)這個錯誤

This application's application-identifier entitlement does not match that of the installed application. These values must match for an upgrade to be allowed

解決方法:
1、Xcode-Window->Devices
2、選中你的設(shè)備,在右邊的installed Apps中刪除這個App
3、重新編繹即可

26 addSubview和insertSubview的理解(自己記錄便于查詢)

  addSubview是一層一層往上加,新加的只能放到父視圖的最上層, 
  insertSubView可以控制它添加到父視圖的哪一層 

A addSubview B  是將B直接覆蓋在A的最上層 

A insertSubView B AtIndex:2 是將B插入到A的子視圖index為2的位置(最底下是0) 

A insertSubView B aboveSubview:C  是將B插入A并且在A已有的子視圖C的上面 

A insertSubView B belowSubview:C  是將B插入A并且在A已有的子視圖C的下面

27 如果你發(fā)現(xiàn)自己的iPhone模擬器慢慢吞吞的,做什么都很慢,那你應(yīng)該打開了這個:

image.png

建議關(guān)閉后試試!

聲明:這些知識也都是我用到過然后從網(wǎng)絡(luò)上找的別人的,主要是方便自己查閱。順便分享出來希望可以幫到正好需要的朋友!

最后編輯于
?著作權(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)容