我遇到了崩溃,很可能与我无法发现的内存管理有关。
崩溃从来没有发生在我身上,我只知道它的发生是因为我收到了崩溃报告。
这也意味着我必须确认崩溃已修复的唯一当前方法是发布应用程序并等待崩溃报告出现(坏消息)或不出现(我很高兴!)。
崩溃报告摘录:
Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR at 0x9
Crashed Thread: 0
Thread 0 Crashed:
0 CoreFoundation 0x375f29e8 0x375e4000 + 59880
1 MyApp 0x000bf22f -[UIViewController(AddressPicker) fullNameAndAddressFromPerson:identifier:] (UIViewController+AddressPicker.m:108)
2 MyApp 0x000bf3f9 -[UIViewController(AddressPicker) guessedUserAddress] (UIViewController+AddressPicker.m:161)
3 MyApp 0x0009cc99 -[RecipientsViewController loadUserAddressFromMyAppSender] (RecipientsViewController.m:190)
4 MyApp 0x0009c189 -[RecipientsViewController viewDidLoad] (RecipientsViewController.m:78)
5 UIKit 0x31a5e541 0x31a3c000 + 140609
原代码:
- (NSString *) fullNameAndAddressFromPerson:(ABRecordRef) person identifier:(ABMultiValueIdentifier) identifier {
NSMutableString *address = [NSMutableString new];
// Get and add first and last name
CFStringRef cfFirstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *firstName = (NSString *)CFBridgingRelease(cfFirstName);
CFStringRef cfLastName = ABRecordCopyValue(person, kABPersonLastNameProperty);
NSString *lastName = (NSString *)CFBridgingRelease(cfLastName);
[address appendFormat:@"%@ %@\n", firstName ?: @"", lastName ?: @""];
// Get and add address
ABMultiValueRef addressMultiValue = ABRecordCopyValue(person, kABPersonAddressProperty);
CFTypeRef addressRef = ABMultiValueCopyValueAtIndex(addressMultiValue, ABMultiValueGetIndexForIdentifier(addressMultiValue, identifier)); // This is line 108
CFRelease(addressMultiValue);
NSDictionary *addressDictionary = (NSDictionary *) (CFBridgingRelease(addressRef));
if ([addressDictionary isKindOfClass:NSDictionary.class]) {
[address appendString:ABCreateStringWithAddressDictionary(addressDictionary, YES)];
}
return [address stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
}
更新代码,包括 Nirav 建议的检查:
- (NSString *) fullNameAndAddressFromPerson:(ABRecordRef) person identifier:(ABMultiValueIdentifier) identifier {
NSMutableString *address = [NSMutableString new];
NSString *firstName, *lastName;
// Get and add first and last name
if (person) {
CFStringRef cfFirstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
if (cfFirstName) {
firstName = (NSString *)CFBridgingRelease(cfFirstName);
}
CFStringRef cfLastName = ABRecordCopyValue(person, kABPersonLastNameProperty);
if (cfLastName) {
lastName = (NSString *)CFBridgingRelease(cfLastName);
}
}
[address appendFormat:@"%@ %@\n", firstName ?: @"", lastName ?: @""];
// Get and add address
ABMultiValueRef addressMultiValue = ABRecordCopyValue(person, kABPersonAddressProperty);
CFTypeRef addressRef;
if (addressMultiValue && identifier) {
addressRef = ABMultiValueCopyValueAtIndex(addressMultiValue, ABMultiValueGetIndexForIdentifier(addressMultiValue, identifier));
CFRelease(addressMultiValue);
}
NSDictionary *addressDictionary;
if (addressRef) {
addressDictionary = (NSDictionary *) (CFBridgingRelease(addressRef));
if ([addressDictionary isKindOfClass:NSDictionary.class]) {
[address appendString:ABCreateStringWithAddressDictionary(addressDictionary, YES)];
}
}
return [address stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
}
我想我错过了显而易见的东西,所以我不会只是回复“呃,你是对的”,我会接受可能修复错误的答案并指出这段代码可以解决的问题变得更安全和改进。
最佳答案
我在做类似的事情时遇到了类似的崩溃,这就是我所做的:
等等。要点是在桥接宏之前执行空检查。
这是为了处理没有填充某些字段的电话簿记录,仅此而已。
关于ios - AddressBook - iOS 应用程序崩溃,启用 ARC,接近 CF 对象操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14655399/
对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr
当我在Rails控制台中按向上或向左箭头时,出现此错误:irb(main):001:0>/Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in`blockin_rl_dispatch_subseq':invalidbytesequenceinUTF-8(ArgumentError)我使用rvm来管理我的ruby安装。我正在使用=>ruby-2.0.0-p247[x86_64]我使用bundle来管理我的gem,并且我有rb-readline(0.4.2)(人们推荐的最少
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
在启用Rack::Deflater来gzip我的响应主体时偶然发现了一些奇怪的东西。也许我遗漏了一些东西,但启用此功能后,响应被压缩,但是资源的ETag在每个请求上都会发生变化。这会强制应用程序每次都响应,而不是发送304。这在没有启用Rack::Deflater的情况下有效,我已经验证页面源没有改变。我正在运行一个使用thin作为Web服务器的Rails应用程序。Gemfile.lockhttps://gist.github.com/2510816有没有什么方法可以让我从Rack中间件获得更多的输出,这样我就可以看到发生了什么?提前致谢。 最佳答案