Xcode 升級後,經常遇到的遇到的警告、錯誤,解決方法

從sdk3.2.5升級到sdk 7.1中間廢棄了不少的方法,還有一些邏輯關係更加嚴謹了。
1,警告:「xoxoxoxo」  is deprecated
解決辦法:查看xoxoxoxo的這個方法的文檔,替換掉這個方法便可。

2,警告:Declaration of "struct sockaddr" will not be visible outside of this function
解決辦法:在你的開源.m文件中添加 #import

3,警告:Implicit conversion from enumeration type 'UIInterfaceOrientation' to different enumeration type 'UIDeviceOrientation'
解決辦法:類型不匹配。跳到出錯的那一行,UIInterfaceOrientation強制轉換爲UIDeviceOrientation就好了。

4,警告:incompatible pointer types assigning to 'MyArrayList*'from 'NSMutableArray'
解決辦法:加入強制轉換(MyArrayList*)

5,警告:'&&' within '||'
問題出處:
    if (exists && !isDirectory || !exists)………
  解決辦法: if ((exists && !isDirectory) || !exists)………

6,警告:Warning:The Copy Bundle Resources build phase contains this target's Info.plist file
解決辦法:將Info.plist文件移到Resources目錄下,而不要直接放在target下。


7,警告:在使用ASIHttp…第三方庫的,運行報錯。
解決辦法:看你的項目中是否添加CFNetwork.framework、SystemConfiguration.framework, MobileCoreServices.framework,
CoreGraphics.framework和libz.1.2.3.dylib,若是是sdk5.0以上,改添加libz.1.2.5.dylib

 8,警告:xxxooo,missing required architecture i386 in file 
解決辦法:若是是錯誤信息的話:
Target->Build Settings->Search Paths, 刪除FrameworkSearch Paths 裏面內容就能夠了。
要只是一個警告的話,真機調試能夠過。具體解決方法待大神出現。 

9,警告:
clang: error: no such file or directory: '/demo2/控件代碼/13/Recorder/Recorder_Prefix.pch'
clang: error: no input files
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang failed with exit code 1

解決辦法: 在你的主工程文件 target搜素,pch ,找到Prefix Header    把它後面的值,都刪除,再運行就解決了。

10,警告:
「ARC forbids synthesizing a property of an Objective-C object with unspecified ownership or storage attribute
解決辦法:若是定義了ARC有效,那麼必需要有全部者屬性的定義;因此代碼改爲下面這樣
@property (nonatomic, strong, readonly) NSString *ss; 

11,警告:
io6一下的xib系統均沒有自動選擇Use Autolayout, Supporting iOS 5 and below with xib of iOS 6 
解決辦法:Just un-select 「Use Autolayout」 in the file inspector of the xib’s view and we are back to the familiar autosizing in size inspector and boom, it supports iOS 5 and below.

12,警告:
Warning: Multiple build commands for output file xxx.png 
解決辦法:找到項目裏xxx.png重複,刪除重複的資源。

//如下是升級到 xcode 5.0.1 以後使用遇到的警告
13,警告:
 「iOS 模擬器」未能安裝此應用程序。
解決辦法:刪除模擬器上當前要運行那個APP,從新運行項目。就ok

14,警告:
SpringBoard沒法啓動應用程序 錯誤:-3
解決辦法:退出模擬器,從新運行這個項目。

15,警告:
The server certificate failed to verify.   
解決辦法:
一、打開終端(實用工具 -->終端),在終端中輸入以下命令:
svn ls https://192.100.1.11?0/svn/xxxxxx(注意下面的url更換成你本身的url地址)
而後直接輸入 「 p 」  確認,就能夠從新鏈接了。

16,警告:
Bitmasking for introspection of Objective-C object pointers is strongly discouraged.   
解決辦法:
某數字& 0x1的時候是表明要取最低位是否爲1,改爲了  if(JK_EXPECT_F(((NSUInteger)object)%2))便可。

17,警告:
Implicit conversion loses integer precision: 'unsigned long' to 'CC_LONG' (aka 'unsigned int').   
解決辦法:
    CC_MD5(str,strlen(str), r);,改爲了     CC_MD5(str, (CC_LONG)strlen(str), r);便可。

18,警告:
error: failed to launch '/private/var/mobile/Applications/xxxxx' -- failed to get the task for process 11140.  
解決辦法:
    重啓你的開發手機便可,還有一種多是你的開發者證書與發佈證書搞錯了,檢查在xcode中證書是否一直 。

遇到相關的警告,通常編譯器都會提供解決方案,因此,做爲新手,咱們應該看懂編譯器給咱們的提示,這樣咱們解決問題就會事半功倍。ios

 
1,  錯誤信息:
   "_OBJC_CLASS_$  xxxxx  ", referenced from:
      objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
解決方法:
  查看工程,看是否是沒有導入相關的框架。或者工程裏添加的有相同".m",".h" 文件

2,  錯誤信息:
Couldn't register dy.CKRiLiText with the bootstrap server. Error:  unknown error code.
This generally means that another instance of this process was already running or is hung in the debugger.Current language:  auto; currently objective-c
解決方法: 多是電腦內存問題引發,重啓電腦便可解決。若是重啓解決不了問題,那就是你剛剛改動的代碼引發的問題。

3 、 錯誤信息:
ios 5是調試正常ios 6真機調試的時候,出現以下錯誤: ld: file is universal (3 slices) but does not contain a(n) armv7s slice: /Users/mac4/Desktop/my desktop/My app/MyApp name 20:09:12  /MyApp name/ZBarSDK/libzbar.a for architecture armv7s error: linker command failed with exit code 1 (use -v to see invocation)
解決方法:在Xcode裏,點擊相應的Target,而後點Build Settings,找到VALID_ARCHS,看裏面的是否是arvm7s,若是不是改爲arvm7s就能夠了。

4 、 錯誤信息:
 error: receiver type 'ViewController' for instance message does not declare a method with selector 'hideSearchBar:' [4]
ViewController 中沒有聲明一個方法選擇'hideSearchBar:
解決方法:
在ViewController .h 中聲明一下這個方法 「  hideSearchBar 」  便可。

五、 錯誤信息:當json從服務端請求時獲得的字符串,若是這樣寫的話,會報錯, ';' after top level declarator
NSString *ss= @"{"recommend":"世界末日","
dogname ":"機器人"}";  
解決方法:
就是,把   「   替換成  \"  便可。
NSString *ss= @"{  \" recommend  \" :  \" 世界末日  \" ,  \" dogname  \" :  \" 機器人  \" }";  

6 、 錯誤信息:
 error: Existing instance variable '_datasource' for property 'datasource' with  assign attribute must be __unsafe_unretained

解決方法:
     id _datasource; 改成     __unsafe_unretained id _datasource:便可
 
31警告:
 warning: Semantic Issue: Incompatible integer to pointer conversion assigning to 'BOOL *' (aka 'signed char *') from 'BOOL' (aka 'signed char')

解決辦法: 檢查 BOOL *換爲BOOL就能夠了,檢查是否是多寫一個   *  號。


32:Jsonkit中的警告

Direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()
object->isa 替換爲 object_getClass(object)
keyObject->isa 替換爲 object_getClass(keyObject)
(id)keys[idx]->isa 替換爲 object_getClass((id)keys[idx])

format specifies type 'unsigned long' but the argument has type 'nsuinteger' (aka 'unsigned int')
給變量增長(unsigned long)進行類型轉換


33:md5加密(iOS SDK中自帶了CommonCrypto

Implicit declaration of function 'CC_MD5' is invalid in C99

[plain] view plaincopy

    #define CC_MD5_DIGEST_LENGTH 16  
    +(NSString *)MD5HashForString:(NSString *)input {  
        const char *cStr = [input UTF8String];  
        unsigned char result[CC_MD5_DIGEST_LENGTH];  
        CC_MD5(cStr, strlen(cStr), result);  
        return [NSString stringWithFormat: @"xxxxxxxxxxxxxxxx",  
                result[0], result[1], result[2], result[3],  
                result[4], result[5], result[6], result[7],  
                result[8], result[9], result[10], result[11],  
                result[12], result[13], result[14], result[15]];  
    }  

引入函數定義的頭文件

#import


34:ASIDataDecompressor中的警告

format specifies type  'short' but the  argument has type 'int'

在+ (NSError *)deflateErrorWithCode:(int)code 和 +(NSError *)inflateErrorWithCode:(int)code中

[NSString stringWithFormat:@"Compression of data failed with code %hi",code] 中

將code改成 (short)code,類型轉換


35:Reachability中警告

Using 'stringWithString:' with a literal is redundant

statusString = [NSString stringWithString: @"Not Reachable"]; 

改成:statusString = @"Not Reachable";


36.format specifies type 'id' but the argument has type 'const char *'

NSCAssert(NO, @"Unhandled error encountered during SAX parse. msg is %@", msg);
改成:NSCAssert(NO, @"Unhandled error encountered during SAX parse. msg is %@", [NSString stringWithUTF8String:msg]);

37 Using 'stringWithString:' with a literal is redundant
改成:self.locationInput.text = @"captured change";


38 在項目中設置控件的layer屬性時,會發生錯誤,
"Property 'c' cannot be found in forward class object 'CALayer *",


這時須要引入  #import 。
 
41,錯誤

Error launching remote program: failed to get the task for process   

解決方法:
把真機上的軟件,刪除,而後,clean 一下,從新運行就能夠了。

        
42,真機調試的時候,出現   [attachment=49364]   這正常,可是不識別機器的。

解決方法:

把 , [attachment=49365] 設置爲以上相對應的版本就能夠了。

43,真機調試的時候,出現   ios Broken pipe

解決方法:
:推出xcode
:斷開機器(iphone,ipad,ipod)連接
:重啓iPhone在聯接xcode,就能夠了。
 
iOS真機調試中出現identity(The identity 'iPhone Developer)證書不匹配的問題

提示(null) error: could not read CFBundleIdentifier from Info.plist (null)

新建一個同名工程,拷貝其plist文件,將原工程中的plist文件替換掉便可
相關文章
相關標籤/搜索