Xcode调试常见问题

1. 编译iPad真机时,选择了 Architetures:Standard(armv6) BaseSDK:iPhoneDevice3.2 TargetDeviceFamily:iPad.

若编译出现如下错误:

Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

则修改 GCC4.2CodeGeneral区域中的ComplieForThumb为非选中.

已经有了开发者证书及私钥后,可直接在越狱的手机上调试.

 

2. 编译链接时, "_OBJC_CLASS_$_xxx", referenced from:可能需要重新建立某个类的文件.

    或者:选择项目名,在detail列表中的target列(显示为一个又圆圈),把这个文件的复选选中,或者再次选中.以把它加入到这个target里面来.

 

3.在sdk4.0及以上使用RegexKitLite报'captureCount' was not declared in this scope错误,是在非.m文件中使用了它的原因.

   http://www.cocoachina.com/bbs/read.php?tid=38784&page=e&#a

 

4.there is no sdk with the name or path.

   从网上down的开源代码,结果运行的时候常出现这样的错,并且在deployment中没有ios deployment target 选项.

   http://blog.aztaru.com/2010/10/05/ios%E7%AD%86%E8%A8%98there-is-no-sdk-error/

   尝试 Project/Edit Active Target/ 及 Set Active SDK菜单项,来回切换一下Active Configuration。

 

5.常见的EXEC_BAD_ACCESS,EXC_BAD_INSTRUCTION错误,一般是因为访问已经被release的对象造成的。

在工程中加入NSZombieEnabled 环境变量,并设为启用,则在 EXC_BAD_ACCESS 发生时,XCode 的 Console 会打印出问题描述中,设置方法:双击Executables 下的 可执行模组,在弹出窗口中,Variables to be set in the environment,添加 NSZombieEnabled,并设定为 YES,点击选中复选框启用此变量。

可以再加入 MallocStackLogging 来启用malloc记录,以获得更多的提示来帮助定位问题。

在gdb窗口输入 (格式: shell   malloc_history <id>   <address>)    shell malloc_history 1436 0x5f7fcf0, 也可以在终端中去运行 就要去掉以上的shell 指令 如 malloc_history <id>   <address>

http://www.cocoachina.com/macdev/objc/2011/0219/2661.html

http://www.cnblogs.com/likwo/archive/2011/02/10/1950664.html

应该仅当需要调试内存时,才设置上述环境变量.


在xcode4中,To edit environment variables, go to Menu Product / Edit Scheme…, select the desired configuration (you probably want 'Run') from the left sidebar first and then click on the Arguments tab. Environment variables are configurable there.

 

6.运行一个IPhone程序时,弹出窗口说“程序运行失败,预置描述文件已过期” 。 解决办法是,在Xcode中, window-> Orgnazier -> 你的iphone ->删除带有红*的该程序之前的Profile 。 然后从Xcode运行该程序.


7. 真机编译时报 Code Sign error: The identity doesn't match any valid certificate/private key pair in the default keychain

    修改工程和Targets的get info\build 中的code signing identity为空


8.调试打印

   CFShow(coreFoundationThingy) will print out a description of coreFoundationThingy to the console. Output looks something like: {value = w:1186.000000 h:687.000000 type = kAXValueCGSizeType}
   If NSLog() is printing something out as an NSCFType, try CFShow().

 

9. 编译时报 Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang failed with exit code 1,修改C/C++ Compiler Version为gcc4.2


10.this class is not key value coding-compliant for the key viewController

可能在创建了一个基于view的工程,而后把生成的viewcontroller删除了,但是在.xib中还有对它的引用,在IB中直接用delete键删除掉它就行了。


11.这台电脑上已经存在一个名为“embedded.mobileprovision”的预置文件,您是否要替换么?

http://blog.sina.com.cn/s/blog_6907b67f0100o2vw.html


12.真机调试时报failed to upload *.app

http://hi.baidu.com/%CB%E6%B7%E7_1989/blog/item/9649f49f805f05aec8eaf466.html

http://www.shouyanwang.org/thread-462-1-1.html


13.记的release时,先置delegate为nil。


14.模拟器

     将xcode升级到4.3.1以后发现,ipad的模拟器,没有Home键了。Command+Shift+H就可以实现类似点击Home键的效果了。


How to “add existing frameworks” in Xcode 4?

  1. In the project navigator, selectyour project
  2. Select your target
  3. Select the 'Build Phases' tab
  4. Open 'Link Binaries With Libraries'expander
  5. Click the '+' button
  6. Select your framework
  7. (optional) Drag and drop the addedframework to the 'Frameworks' group

15.如何在Xcode 4.2 下进行 iPod touch 2代、iPhone 3G等设备的真机调试?
     http://dev.ppios.com/2012/02/%E5%A6%82%E4%BD%95%E5%9C%A8xcode-4-2-%E4%B8%8B%E8%BF%9B%E8%A1%8C-ipod-touch-2%E4%BB%A3%E3%80%81iphone-3g%E7%AD%89%E8%AE%BE%E5%A4%87%E7%9A%84%E7%9C%9F%E6%9C%BA%E8%B0%83%E8%AF%95%EF%BC%9F/


16.编译真机提示provising文件找不到,到project.pbxproj中,把那串标识值删除。


17.在xcode4.3上连接装有ios4.2的3gs,提示: Xcode has encountered an unexpected error (0xC002)
No such file or directory, at ‘/SourceCache/DTDeviceKit/DTDeviceKit-1196/DTDeviceKit/DTDeviceKit_Utilities.m:798’

     http://stackoverflow.com/questions/7922308/xcode-4-2-error-0xc002-when-trying-to-use-a-jailbroken-iphone-3g-for-develop

cd ~/Library/Developer/Xcode/iOS\ DeviceSupport/4.2.1\  8C148a /Symbols/System/Library/Caches/com.apple.dyld/
touch .copied_dyld_shared_cache_armv6
touch .processed_dyld_shared_cache_armv6
touch dyld_shared_cache_armv6
或 
touch .copied_dyld_shared_cache_armv7
touch .processed_dyld_shared_cache_armv7
touch dyld_shared_cache_armv7


18. xcode4添加调试断点  
     在Xcode左侧断点管理窗口(Command+6)中,点击左下角+,添加add symbolic breakpoint,输入objc_exception_throw,点击done;然后右键单击该断点选择move breakpoint to,选择项目名或User,即可以在所有项目中起作用。
    还可添加输入malloc_error_break的symbolic断点,以跟踪调试释放了2次的对象。


19.XCode内置GDB,调试时在输出窗口中使用GDB命令来调试程序。

     po 命令:为 print object 的缩写,显示对象的文本描述(显示从对象的 description 消息获得的字符串信息)。

     print 命令:有点类似于格式化输出,可以输出对象的不同信息:

     info 命令:我们可以查看内存地址所在信息

     show 命令:显示 GDB 相关的信息。如:show version 显示GDB版本信息

     help 命令:如果忘记某条命令的语法了,可以使用 help 命令名 来获取帮助信息。如:help info 显示 info 命令的用法。


20.NSLog

    真机上NSLog会消耗资源,

    以release模式编译的程序不会用NSLog输出,而以debug模式编译的程序将执行NSLog的全部功能。

#ifndef __OPTIMIZE__
# define NSLog(...) NSLog(__VA_ARGS__)
#else
# define NSLog(...)
#endif


#ifdef __OPTIMIZE__
#define NSLog(...) 
#endif

  这个代码的魔术在于:release模式通常会定义 __OPTIMIZE__,debug模式不会。将这段代码放在头文件当中,就可以放心的使用NSLog了!

  把这些代码放到*Prefix.pch中最省事。可以把这段宏定义放到一个头文件中,再把这个头文件包含到*Prefix.pch中。

    http://lichen1985.com/blog/?p=251

   iOS中日志打印:

   自定义NSLog  #define NSLog NSLog(@"#%s##%d#",strrchr(__FILE__,'/'),__LINE__);NSLog,例如NSLog(@" begin main function"); 打印出来如下 #/main.mm##30# begin main function

   参考 http://xcodev.com/wordpress/?m=201204


21. 错误日志目录在Mac OS X: ~/Library/Logs/CrashReporter/MobileDevice/<DEVICE_NAME>


      iOS Exception caught Crash Report,3种方法

      http://blog.sina.com.cn/s/blog_67b7cb7b010146qj.html

      在iPhone上捕获软件异常退出的信息,2种方法

      http://hi.baidu.com/coolwidy/blog/item/76f006896168ecb80f2444e7.html

      PLCrashReporter

      http://caydenliew.com/2011/11/plcrashreporter-the-iphone-crash-framework/

  

     http://blog.sina.com.cn/s/blog_60b45f230100tn5b.html


22. Certificate identity 'iPhone Developer: XXXXXXXX' appears more than once in the keychain. The codesign tool requires there only be one
       出错原因:多次为同一个计算机生成私有证书,并且每次都生成了proversionning文件,下载并按照到同一个iOS设备上,那么再次编译程序到设备上的时候就会出现这个问题。
      修改方法:在Xcode中,选择菜单Window->Organizer,在LIBRARY下面,选择Provisioning Profiles.找到前面几次生成的Provisioning profiles.删除。
                        在系统的keychains,即钥匙串管理程序中,在登录下面,我的证书,删除早期的私有证书。
                        再次编译


23.在 iOS 设备上测试你的应用

     http://www.guomii.com/posts/20637

     如果你已加入 iOS 开发者计划,你现在就可以使用 Xcode 进行真机运行、测试和调试了,直接在xcode4中操作。

     当你将一台安装了有效描述文件的设备,连接到 Mac 上时,这台设备的名称以及当前系统版本会出现在Edit Scheme的Destination 菜单中。


24.error: failed to launch '/Users/gzty1/Library/Developer/Xcode/DerivedData/TianyaQing-chiobhpmbvwnqudfqnfawdzjrtey/Build/Products/Debug-iphoneos/TianyaQing.app/TianyaQing' -- failed to send the qLaunchSuccess packet

   重新从appstore上下载安装此软件,再删除,然后尝试真机调试




Xcode 是苹果公司的集成式开发环境(IDE),可以同时用来开发 iOS 和 Mac OS X 应用程序。当你在 Mac 电脑上安装 Xcode 之后,同时也会安装 iOS SDK,其中包含了 iOS 平台开发所需的接口等。

   在线安装下载地址 https://developer.apple.com/xcode/index.php

   下载地址 登录进入 connect.apple.com,就可以看到下载列表


1. 编译项目时常报如  Undefined symbols:
".objc_class_name_PlacardView", referenced from:
literal-pointer@__OBJC@__cls_refs@PlacardView in MoveMe2View.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

这样的错误.

 

解决方法参考下文:

That has happened to me a lot of times. That error is caused when the compiler can't find a class or function. Besides the obvious reasons for that to happen, you should also do something like this:

On the left of the Xcode window go to the targets, and find your application. Open it. You should see a build phase named "Compile Sources". Make sure that your implementation file is included inside that build phase. If not, drag and drop it onto that build phase.

Also, make sure that you have all frameworks included and linked to your application! To make that sure, go into your application target again, and see the "Link Binary With Libraries" build phase. See if all necessary .framework files are in there. If not, add them using drag and drop.

 

在项目的Groups&Files窗口中,打开Targets/项目名 /Compile Sources/把提示找不到的源文件拖到这里.重新编译.

 

2.接上手机(版本 4.2.1 8c148a),在Organizer中,报The version of iOS  ...  does not match any of the versions of iOS supported...,重启手机,xcode都不能解决。最后,重装xcode_3.2.5_and_ios_sdk_4.2_final.dmg。

 

3.设置字体大小:

1)打开Preferences,快捷键是“Command +,”(注意,是三个键,按住command键,然后再快速地按“+”和“,”两个键即可)

2)选择“Fonts &Colors”,选中所有的“Category”,然后双击“Font”一列,在弹出的对话框中选择适合自己的字体大小即可。


4.重构

包括重构变量名,方法名,和类名。

选择变量名,点击Edit\Refactor\Rename...,要在输入框内输入新名字后,点Preview,然后Preview变成Apply,点击Apply。

http://blog.csdn.net/f520131480315/article/details/6457927


5.快照

    一般在开始重构之前要备份,选择File-Make Snapshot,Xcode会记住项目当前的状态。如果发现代码被改得面目全非,选择File-Snapshot,回到做快照的那一刻。

如果发现提示:Snapshot Failed:A project snapshot cannot be created. 可能是一个磁盘镜像文件被损坏了,它用来存储快照,可以到~/Library/Application Support/Developer/Shared/SnapshotRepository.sparseimage 把镜像文件删掉,然后重启xcode。

    如果发现修改了某些代码之后出了问题,利用 Xcode 快照(snapshot)功能就可以轻松恢复工程到之前的状态,甚至已删除的工程也可以。快照会保存当前工程的所有状态到磁盘上,以备之后进行恢复。Xcode 的工程管理器中列出了所有可用的快照。

    可以随时手动创建快照,也可以让 Xcode 根据场合自动创建快照,例如每次构建之前或通过查找并替换修改代码之前等。

     File > Create Snapshot,输入此快照的名称和描述,点按 Create Snapshot。
此快照就会出现在工程管理器中了。要恢复到此快照,请点选 File > Restore Snapshot。


6.help\search

 用来查找在菜单中的功能,命令等。

 

7.在svn上增加目录时,用import.

 

8. 修改某个文件时,弹出

This file is not writable. You could either perform an SCM Edit operation on this file, or allow editing anyway. You may not be able to save your changes, but you will be able to Save a Copy somewhere else.

是由于在本地锁定了文件,显示简介 ,去掉勾选已锁定。

 

9. 制表符替换成2个空格,在编写程序代码时用空格代替Tab,可以避免由于编辑器对tab显示方式不同引起的代码错乱,是一种良好的编程风格

Xcode Preferences->Indentation 把indent width设置为2个空格。


10.格式化代码

    Edit - Format->Re-Indent

   在Xcode\Preferences...\ key bindings\拷贝一份xcode default\编辑Re-Indent 同时按下想要设置的快捷键。


   In Xcode 4, it's been moved to Editor (注意是Editor,不是Edit)> Structure > Re-Indent command (and has a default shortcut of CTRL+I ),默认快捷键是 Ctrl加i。它好按且未与其它快捷键冲突,所以不需要修改。


11.打不开工程文件时,打开project.pbxproj,查找冲突mine,删除冲突标记。


12.换过证书,提示provising文件问题,在 project.pbxproj 中查找提示那串码,删除掉这串码保存。

 

13.xcode 4.2 svn问题

    在Respotitories中选中工程目录后,点update,弹出对话框,"Error validating server certificate for  googlecode.com:443.......",解决办法:

    比如用浏览器登录 http://code.google.com/p/.../source/checkout,复制 svn checkout https://xxx.googlecode.com/svn/trunk/ xxx --username xxx,到控制台中运行,提示Error validating server certificate for 'https://xxx.googlecode.com:443':
 - The certificate is not issued by a trusted authority. Use the
   fingerprint to validate the certificate manually!
Certificate information:
 - Hostname: *.googlecode.com
 - Valid: from Wed, 11 Apr 2012 00:04:01 GMT until Thu, 11 Apr 2013 00:14:01 GMT
 - Issuer: Google Inc, US
 - Fingerprint: cb:f1:c8:ac:28:d5:61:b7:c1:9c:73:7e:3a:b6:bb:e2:e6:55:95:2a
(R)eject, accept (t)emporarily or accept (p)ermanently?  输入p,开始checkout,然后到xcode中,发现也可以成功执行更新了。


  但在提交上,仍然弹出  Authentication realm: <https://xxx.googlecode.com:443> Google Code Subversion Repository
Password for '用户名': 
Authentication realm: <https://xxx.googlecode.com:443> Google Code Subversion Repository
Username: svn: Commit failed (details follow):
svn: MKACTIVITY of '/svn/!svn/act/19511c13-1823-4c4e-a551-3e0dfd8c0510': authorization failed: Could not authenticate to server: rejected Basic challenge (https://xxx.googlecode.com)


14.在xcode4.2中,

      Product -> Profile 再选择leaks,启用内存泄漏监测。

      相比之下,Product \ Analyze 是更好的工具,它分析一些垃圾代码,及潜在的内存泄漏,并且指出精确的代码行。可以看出,它建议所有自定义函数都返回自动释放的对象,否则会被列入潜在的内存泄漏中,potential leaks。

    添加framework,

  1. In the project navigator, selectyour project
  2. Select your target
  3. Select the 'Build Phases' tab
  4. Open 'Link Binaries With Libraries'expander
  5. Click the '+' button
  6. Select your framework
  7. (optional) Drag and drop the addedframework to the 'Frameworks' group

      且在xcode4中新建工程时,去掉Use storyboards,Use ARC,include Unit Tests三个复选。


15.  编译可执行文件时,报object file format invalid or unsuitable

       打开终端:

       sudo su 

       查看/usr/bin目录下是否存在codesign_allocate程序,如果存在,执行改名操作
       sudo mv /usr/bin/codesign_allocate /usr/bin/codesign_allocate_old

       将xcode目录下的codesign做一个软链接
       sudo ln -s /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate /usr/bin


16. 真机调试时,提示 No provisioned IOS devices are available.Connect an IOS device or choose an IOS simulator as the destination.

      修改IOS Deployment Target,不要高于真机的版本。

http://rainbird.blog.51cto.com/211214/646828


17.添加预定义宏

    打开工程 Project--->Edit Project Editting(选着build)选项--->找到GCC Preprocessing->Preprocessor Macros ,例如设置其值为DEBUG=1


18.xcode4中修改编译生成文件的位置

   File\project settings\Derived data location\,选择Project-relative,输入文件夹名字


19. 真机调试报 error: failed to launch '/Users/gzty1/Library/Developer/Xcode/DerivedData/应用名-chiobhpmbvwnqudfqnfawdzjrtey/Build/Products/Debug-iphoneos/应用名.app/应用名' -- No such file or directory (/Users/gzty1/Library/Developer/Xcode/DerivedData/应用名-chiobhpmbvwnqudfqnfawdzjrtey/Build/Products/Debug-iphoneos/应用名.app/应用名)

     出现的原因可能是正在从appstore上安装此程序,同时又在真机调试安装些程序,导致后面真机调试安装此程序一直失败。

     解决方法:重新完成从appstore上安装此程序后,再尝试真机调试安装。

 

20. Xcode 提供了一系列用来管理整个开发流程的工具,从创建应用到测试、优化应用,直至上传应用到 App Store。

      http://www.guomii.com/posts/20273

      原英文版地址

      https://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/Tools/CreateYourAppinXcode/StartYourProjectinXcode/StartYourProjectinXcode.html

      本《iOS应用开发入门指南》译自苹果官方的 Start Developing iOS Apps Today 系列教程。

      http://www.guomii.com/posts/20250


      Provisioning Portal 配置门户

      在创建新工程向导中,Class Prefix,应用委托就会被命名为 [Class Prefix]AppDelegate


21.Storyboards,故事板

     故事板里包含了定义此应用程序用户界面的对象、过渡(Transition)以及连接(Connection)。查看源文件发现MainStoryboard.storyboard是xml格式的内容。

     http://www.guomii.com/posts/20868

     利用 Xcode 检视器(Inspector),来观察视图控制器的状态等信息。

     需要注意的是,当选择一个视图时 Xcode 会将其高亮显示,此时画布中的颜色因为叠加可能会和 Colors 窗口中所选的颜色不完全一致。

     对齐引导线,它们能帮你轻松在视图中将 UI 元素对齐到边界或中心位


22.IBActionOutlet

    在 Xcode 中,给某个 UI 元素添加动作并设定相应的动作方法的途径是:按住 Control 键,并从画布上的该元素拖动到合适的源文件上(一般而言就是视图控制器的源文件)。故事板会把通过这种方式建立的连接进行存档。之后,当应用运行载入故事板时,这些连接就会被还原出来。

   在 Xcode 工具条里,点按 Utilities(实用工具)按钮关闭实用工具区域,然后点按辅助编辑器按钮(Assistant Editor)调出辅助编辑器面板。
确保辅助编辑器里显示的是视图控制器的头文件。在画布中,按住 Control 并从 Hello 按钮拖动到 HelloWorldViewController.h 的方法声明部分(即 @interface 语句到 @end 语句之间的部分)。

   在非苹果键盘上control键依然是Ctrl键。
   IBAction 是一个特殊的关键词,用来告诉 Xcode 把一个方法当成目标-动作连接来看待。IBAction 被定义为 void

   插座变量(Outlet)描述的是两个对象之间的连接。当你需要让一个对象(例如视图控制器),与它所包含的一个对象(例如文本框)进行沟通时,你就会把被包含的那个对象称为插座变量。当应用运行起来时,你在 Xcode 里创建的插座变量就被还原出来了,这样在运行时这些对象就可以相互交流了。

   给文本框设置委托对象:按住 Control 键并从文本框拖动到场景坞里的黄色球体上(黄色球体代表视图控制器对象),当半透明面板出现时,选择 Outlets(插座变量)部分的delegate


23.源代码控制管理(SCM)

     能够提供比快照更加细致入微的变更跟踪管理。(如果你在团队中与他人协同工作,源代码控制管理还能帮你提高团队效率。)SCM 系统会在磁盘中对每个文件保存多个版本,并存储各个文件各个版本的元数据到 SCM 仓库中。

     Xcode 支持两种流行的 SCM 系统:Git 和 Subversion。Xcode 包含了一个版本编辑器,无论使用哪种 SCM 系统都可以轻松对比保存在仓库中文件的不同版本。如果你发现代码中出现了漏洞,则可以将最新的版本和之前的某个正常运行的版本拿来比较,让你捉出产生问题的“臭虫”。




24.分发和发布应用
     Xcode 能够让你轻松地将尚未正式发布到 App Store 的应用分享给测试者们。要分发应用,请在方案编辑器中创建一个应用归档。然后就可以使用 Xcode 的归档管理器来让测试者们分享你的应用。

     当你准备正式发布应用的时候,可以先使用归档管理器来评估一下你的应用能否达到 App Store 审核的标准。这项评估能够通过则可以保障正式审核过程尽可能地快速。然后就可以在 Xcode 正式向 App Store 提交你的应用了。


学习进度

http://www.guomii.com/posts/20284


25.在instruments中查看内存

    

The Living bytes, or Net bytes is how much memory your application is using at the time you select in the timeline. That will include leaked memory, since leaked memory is never deallocated.

#Living is how many allocations of a certain size/object type happened (and are still allocated). This is very useful when looking for leaks. For example, if you repetitively perform an action (like coming in an out of a modal view controller), and you see that #Living of an object grows by the same amount each time, then you're probably leaking those objects. You can then confirm by drilling down and seeing the exact line of code that is allocating the objects, and even see the time index each one was created.

Overall bytes includes memory that has been released. It's useful to track that number for performance optimization purposes, but not if you're just trying to see your current memory footprint or look for leaks.


笔画输入面板打开后,内存使用增加了20M


苹果bug--获取键盘有内存泄露问题
memory leaks in open_handle_to_dylib_path and UIKeyboardInputManagerClassForInputMode
If you're developing an iPhone app that uses UITextField objects and you're rigorous enough to check for memory leaks using Instruments, chances are you'd discover some leaks in UIKit and CoreGraphics libraries, stemming from some allocations done in dyld::mkstringf, called from dyld::loadPhase5.
According to some reports found on the web, it seems that this is a bug in the tools from Apple, and it appears only on the simulator, not when testing on the actual device. So you could safely ignore it. In any case you couldn't do anything about it, as the traceback leading to the leak goes through code outside of your control, that is, unless you happen to work for Apple :).


26.安装后可以看到还有一个dashcode,它用于web开发

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值