草庐IT

iphone - 仅在设备上运行应用程序时出现崩溃问题

coder 2024-01-27 原文

所以我有一个非常奇怪的问题,当我在模拟器上运行我的应用程序并插入 iPad(在插入电缆的设备上运行应用程序)时,它一切正常。但是,在插入设备并尝试使用该应用程序后在设备上运行后,它崩溃了。尝试查看设备崩溃日志,我看到:

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libobjc.A.dylib                 0x3672bf78 objc_msgSend + 16
1   App                     0x000ca834 -[AHAppImageData dealloc] (AHInstagramImageData.m:122)
2   libobjc.A.dylib                 0x3672d16e _objc_rootRelease + 30
3   CoreFoundation                  0x33d792e0 CFRelease + 88
4   CoreFoundation                  0x33d8ea30 -[__NSArrayM removeObjectAtIndex:] + 288
5   CoreFoundation                  0x33d84adc -[NSMutableArray removeAllObjects] + 64
6   App                     0x000f717e -[AHImageDataSource clearDataSource] (AHImageDataSource.m:53)
7   App                     0x000c0a36 __49-[AHMainViewController loadRequestWithURLString:]_block_invoke_0 (AHMainViewController.m:91)
8   libdispatch.dylib               0x32658c52 _dispatch_call_block_and_release + 6
9   libdispatch.dylib               0x3265aee0 _dispatch_main_queue_callback_4CF$VARIANT$mp + 188
10  CoreFoundation                  0x33e032a6 __CFRunLoopRun + 1262
11  CoreFoundation                  0x33d8649e CFRunLoopRunSpecific + 294
12  CoreFoundation                  0x33d86366 CFRunLoopRunInMode + 98
13  GraphicsServices                0x37d68432 GSEventRunModal + 130
14  UIKit                           0x36820cce UIApplicationMain + 1074
15  App                     0x000b2860 main (main.m:16)
16  App                     0x000b2820 0xb1000 + 6176

知道为什么这只发生在设备上,而不是在插入或模拟器运行应用程序时发生吗?

根据下面的评论,我展示了对此负责的代码:

 [[AHMyAppAPIClient sharedClient] getPath:requestURLPath parameters:nil 
             success:^(AFHTTPRequestOperation *operation, id response) {
                 [self.progressHUD_ hide:YES];


                 self.nextPaginationURL_ = [[response valueForKey:@"pagination"] valueForKey:@"next_url"];

                 [self.collectionView_.pullToRefreshView stopAnimating];
                 [[NSOperationQueue sharedOperationQueue] cancelAllOperations];


                 NSArray *arr = [response valueForKey:@"data"];
                 if ([arr count] > 0){
                     [[AHImageDataSource sharedDataSource] clearDataSource];
                 }


                for (NSDictionary * data in arr){
                     AHInstagramImageData * imgData = [[AHInstagramImageData alloc] initWithData:data];
                     [[AHImageDataSource sharedDataSource] addObject:imgData];
                     [imgData release];
                 }


                 dispatch_async(dispatch_get_main_queue(), ^{
                     [self.collectionView_ setContentOffset:CGPointMake(0, 0)];
                     [self.collectionView_ reloadData];

                 });

             }
             failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                 [self.progressHUD_ hide:YES];
                 NSLog(@"Error fetching user data!");
                 NSLog(@"%@", error);      

             }];

这是我设置数据源的方式:

extern NSString * const kClearDataSource;

@interface AHImageDataSource : NSObject
+ (AHImageDataSource *)sharedDataSource;
- (void) clearDataSource;
- (void) addObject:(id) object;
- (void) addObject:(id)object atIndex:(int) index;
- (int) count;
- (id) objectAtIndex:(int) index;
@end


NSString * const kClearDataSource = @"clearDataSource";

@interface AHImageDataSource()
{
    NSMutableArray * imageDataSource_;
}

@property (nonatomic, retain) NSMutableArray * imageDataSource_;

@end

@implementation AHImageDataSource
@synthesize imageDataSource_;

+ (AHImageDataSource *)sharedDataSource {
    static AHImageDataSource *_sharedClient = nil;
    static dispatch_once_t oncePredicate;
    dispatch_once(&oncePredicate, ^{
        _sharedClient = [[self alloc] init];
    });

    return _sharedClient;
}


- (id)init {
    self = [super init];
    if (!self) {
        return nil;
    }

    NSMutableArray * temp = [[NSMutableArray alloc] initWithCapacity:200];
    self.imageDataSource_  = temp;
    [temp release];


    return self;
}

-(void) clearDataSource
{
    if ([self.imageDataSource_ count] > 0){
        [self.imageDataSource_ removeAllObjects];
    }

}

- (void) addObject:(id) object
{
    [self.imageDataSource_ addObject:object];
}

- (void) addObject:(id)object atIndex:(int) index
{
    [self.imageDataSource_ insertObject:object atIndex:index];
}

- (int) count
{
    return [self.imageDataSource_ count];
}

- (id) objectAtIndex:(int) index
{
    if (index >= 0 && index < [self.imageDataSource_ count]){
        return [self.imageDataSource_ objectAtIndex:index];
    } 

    return nil;
}

- (void) dealloc
{
    [super dealloc];
    [imageDataSource_ release];
}

@end

编辑:

NSZombieEnabled 似乎隐藏了这个问题。当我禁用 NSZombieEnabled 时,它现在会在模拟器和设备上崩溃。

最佳答案

我同意 Jim 的观点,看起来像是双重发布。

我会利用 Instruments 的“zombie”配置文件来测试这种情况。它只能在模拟器中完成,但应该向您准确显示双重发布的内容。

一旦 100% 清楚了,解决问题通常就很容易了。

关于iphone - 仅在设备上运行应用程序时出现崩溃问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10689969/

有关iphone - 仅在设备上运行应用程序时出现崩溃问题的更多相关文章

  1. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  2. ruby - 在 Ruby 程序执行时阻止 Windows 7 PC 进入休眠状态 - 2

    我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0

  3. ruby - 将差异补丁应用于字符串/文件 - 2

    对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl

  4. ruby - ECONNRESET (Whois::ConnectionError) - 尝试在 Ruby 中查询 Whois 时出错 - 2

    我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.

  5. ruby - 在 64 位 Snow Leopard 上使用 rvm、postgres 9.0、ruby 1.9.2-p136 安装 pg gem 时出现问题 - 2

    我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po

  6. ruby - 通过 rvm 升级 ruby​​gems 的问题 - 2

    尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub

  7. ruby - 如何指定 Rack 处理程序 - 2

    Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack

  8. ruby - 在 Ruby 中编写命令行实用程序 - 2

    我想用ruby​​编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序

  9. ruby - 如何每月在 Heroku 运行一次 Scheduler 插件? - 2

    在选择我想要运行操作的频率时,唯一的选项是“每天”、“每小时”和“每10分钟”。谢谢!我想为我的Rails3.1应用程序运行调度程序。 最佳答案 这不是一个优雅的解决方案,但您可以安排它每天运行,并在实际开始工作之前检查日期是否为当月的第一天。 关于ruby-如何每月在Heroku运行一次Scheduler插件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/8692687/

  10. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

随机推荐