您的位置:首页 > 其它

遇到过——Xcode开发错误、警告⚠️——小集合

2016-09-04 17:23 267 查看
1.
error:
Assertion failure in -[UITextView _firstBaselineOffsetFromTop], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.60.12/UITextView.m
description:
点击Xcode debug view hierarchy,console输出的警告信息,并且hierarchy并不可见。
solution:
在UITextView的category的implementation文件中加入以下两个方法:
@implementation UITextView (Category)

- (void)_firstBaselineOffsetFromTop

}

- (void)_baselineOffsetFromBottom
{   
}
@end
2.
error:
Xcode错误"The working ... has uncommitted changes"解决方案
description:
有时候想切换到其他的branch或者试图执行merge、pull、push等操作,即使未做任何修改,也会报出这个错误,因为真正的内容没有任何修改,因此推测可能是某些状态文件或者描述文件在捣鬼。
solution:
只需要进入项目文件夹目录下,分别执行以下两行代码即可。
git rm --cached *.xcuserstate
git rm --cached *.xcuserdata
3.
error:
Application Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
description:
参考:http://my.oschina.net/vimfung/blog/494687
<
4000
div style="font-family:Menlo;font-size:10px;">solution:

在iOS9 beta中,苹果将原http协议改成了https协议,使用 TLS1.2 SSL加密请求数据。
解决办法:修改info.plist文件



4.
error:
Assertion
failure in -[AFHTTPRequestSerializer requestWithMethod:URLString:parameters:error:] —>reference URL

solution:
NSString*url = [NSStringstringWithFormat:@"http://%@/api",kIp];
加上 —>>> url = [urlstringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
5.
error:
CGContextSetStrokeColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall
degradation of system stability and reliability.
solution:
在DrawRect:里加上以下两句:
CGContextRef *context =  UIGraphicsGetCurrentContext();
UIGraphicsPushContext(context);
6.
error:
"_OBJC_CLASS_$_className", referenced from: 

description:
根据个人经验,推测一般是对应的.m实现文件丢失引起的。定义了.h文件,忘记实现.m也会报这个错误。
solution:

Tagert--Build Phases -- Compile Sources下添加对应的.m文件
或者
实现.m 
@implementation
@end

7.
error:
Assertion failure in -[AFStreamingMultipartFormData
appendPartWithHeaders:body:]
description:
AFN上传图片,发生这个错误:因为在AFN的方法里面写了图片上传
:[formData appendPartWithFileData:imageData name:@"picture" fileName:@"tupian.jpg" mimeType:@"image/jpeg"];
但是当时又没有上传,所以要进行判断。 
solution:
   [manager POST:[NSString stringWithFormat:@"%@node/addNote" , url] parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {

            if (imageData!=nil) {   // 图片数据不为空才传递

            [formData appendPartWithFileData:imageData name:@"picture" fileName:@"tupian.jpg" mimeType:@"image/jpeg"];

            }

        } success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSLog(@"发送成功:%@" , responseObject) ; 

8.error:

Error Domain=AFNetworkingErrorDomain Code=-1016 "Request failed: unacceptable content-type: ….

description:

出现这个错误是因为AFN只支持text/json,application/json,text/javascript这几种格式,

solution:

解决方法有两个:

1.直接在AFURLResponseSerialization.m文件中搜索 
self.acceptableContentTypes,然后直接添加@“text/html",@"text/plain”,@“video/mpeg" 就可以解决问题。
2.代码中添加解决问题
self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html”,@"text/plain" ,@“video/mpeg", nil];

9.

error:
Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with
array or object and option to allow fragments not set.) UserInfo=0x9152780 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
description:
JSON解析错误
solution:
加上以下代码即可:
manager.responseSerializer = [AFJSONResponseSerializer serializer];
10.
error:
The certificate used to sign "XXX" has either expired or has been revoked. An updated certificate is required to sign and install the application.
description:
由于最近频繁更换电脑开发,因此经常遇到这个问题。
在另一台机器上登陆过账号并且真机运行后,本机的证书都会失效,一般情况下,遇到这个问题以后:
1.keyChainAccess中查看是否有过期的证书或者无效的证书
2.到工程的target中选择正确的证书
3.再次运行弹出提示框,并选择Fix issue修复即可解决问题。
这次出现这个问题是因为Xcode从7.3.1升级到Xcode8.0。
首先尝试解决问题
1.查看keyChainAccess并未发现证书失效,target->general->signing中也已经选择正确的证书
2.Xcode->preferences->Accounts,账号正确。Run,仍有问题。
3.Xcode Menu -> preferences -> Account -> Team -> View Details -> Signing Identities ->Mac Development -> Create
4.尝试clean、重启,也没解决问题。
solution:
在网上查询资料后,终于找到解决的方案:
1.clean the project
2.Xcode Menu -> preferences -> Account -> Team -> View Details
3.selectanyprovisioning profile from Provisioning Profiles list -> Right Click
-> Show in Finder
4.select all provisioning profiles and move them to trash
5. ..-> View Detail -> Download All Profiles
Run it again and it should work.
11.
error:
.cxx_destruct crash
description:
release object which is already nil

12.

error:
真机调试情况下:





dyld: Library not loaded: @rpath/IHFKit.framework/IHFKit

  Referenced from: /var/containers/Bundle/Application/DF33E1CB-0A69-4303-A22A-686E643DE922/iDoctors.app/iDoctors

  Reason: no suitable image found.  Did find:

/private/var/containers/Bundle/Application/DF33E1CB-0A69-4303-A22A-686E643DE922/iDoctors.app/IHFKit.framework/IHFKit: code signing blocked mmap() of '/private/var/containers/Bundle/Application/DF33E1CB-0A69-4303-A22A-686E643DE922/iDoctors.app/IHFKit.framework/IHFKit'
Message from debugger: Terminated due to signal 6

description:
此处IHFKit是动态库。
-1.真机调试时动态库签名需与项目签名一致。
-2.若commit的时候把个人用的动态库一起push到分支上,那么teammate拉了代码以后将其本地的动态库签名替换成提交者的签名,与其本地签名不一致,就会导致出现该问题-fatal error @#$%^&*..问题,只需要对动态库重签名一次即可。
-3.keychain中证书一般是两个,一个个人的开发者证书,另一个则是在公司的group中的开发证书。

-4.如果keychain中有其他的过期或其他原因引起的重复失效证书,同样可能会导致fatal error问题。
-5.如果fatal error,最直接的方法就是重签名
-6.查看动态库的签名证书 codesign -d -vv IHFKit.framework    — (在动态库所在目录下的执行该命令)

solution:

动态库重签名步骤:
-1.删除原有IHFKit.framework母包的签名信息



删除_CodeSignature目录

-2.用个人开发证书重签名

1)列出电脑上可用的签名。打开Mac终端,输入
/usr/bin/security find-identity -v -p codesigning
2)根据使用IHFKit的App所使用的签名,对(动态库名).framework重签名。终端输入
codesign -fs “iPhone Developer: xxxx (XXXX)” (动态库名).framework
重签名后的动态库即可用于开发人员真机调试了。

-3.查看动态库的签名证书 codesign -d -vv IHFKit.framework    — (在动态库所在目录下的执行该命令) 

13. 
error:

This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the
app uses this data.
description:
iOS10开发权限问题
solution:
需要在info.plist文件中添加一对key-value属性,key是NSPhotoLibraryUsageDescription,value可随意写。可以直接打开添加,也可以通过SourceCode添加以下
<key>NSPhotoLibraryUsageDescription</key>
<string>photoDescription</string>
还有一些其他可能以为权限引起的问题,可一并添加解决:
<key>NSCameraUsageDescription</key>
      <string>cameraDesciption</string>
<key>NSContactsUsageDescription</key>
      <string>contactsDesciption</string>
<key>NSMicrophoneUsageDescription</key>
      <string>microphoneDesciption</string>
>

14.
error:

 XXXX requires a provisioning profile. Select a provisioning profile for the "Debug" build
configuration in the project editor.
Code signing is required for product type 'Application' in SDK 'iOS 10.1’
description:

由于Xcode8更新了provision profile引起
solution:

1. 到project -> general中修改signing,选中automatically manage signing

2. 选择enable automatic

3.选择相应的开发者账号即可,如下:

15.
error:

Command /Applications/Xcode.app/Contents/Developer/usr/bin/copypng failed
with exit code 2

solution:

打开工程project->BuildPhases->Copy Bundle Resources,找到对应文件删除

16.

error:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x1461f8600 of class UICollectionView was deallocated while key value observers were still registered with it. Current observation
info: <NSKeyValueObservationInfo 0x174434180> (
<NSKeyValueObservance 0x1702454f0: Observer: 0x17015cf60, Key path: collectionViewLayout, Options: <New: NO, Old: NO, Prior: NO> Context: 0x100f29308, Property: 0x170245610>

<NSKeyValueObservance 0x1706499f0: Observer: 0x17015cf60, Key path: contentOffset, Options: <New: NO, Old: NO, Prior: NO> Context: 0x100f2930c, Property: 0x17025d940>

)'

*** First throw call stack:

(0x1846541c0 0x18308c55c 0x184654108 0x1850a1df4 0x1830a5fe0 0x18452ddb8 0x18a718db0 0x18a7393bc 0x1846017dc 0x1845ff40c 0x1845ff89c 0x18452e048 0x185fb1198 0x18a500818 0x18a4fb550 0x10065f130 0x1835105b8)

libc++abi.dylib: terminating with uncaught exception of type NSException

description:

You have to ensure that the view you will assign to 
inputView
 or 
inputAccessoryView
doesn't
belong to any parent view. When you create these views from a xib inside a ViewController, by default they are set as subviews of a superview.

solution:

Use the method 
removeFromSuperview
 on
the view you will assign to 
inputView
 or 
inputAccessoryView


textView.inputView = myInputView;
[myInputView removeFromSuperview];
[textView becomeFirstResponder];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: