iPhone - 在应用程序启动期间,应用程序进入后台

时间:2012-11-21 20:44:57

标签: iphone ios xcode ios6 iphone-4

最近我遇到了一个问题,我的应用程序在首次启动时进入后台,但这只发生在带有iOS6的iPhone 4S上。我测试过:

  • 模拟器,具有不同的硬件/软件配置
  • iPhone 5(iOS 6)
  • iPhone 4S(iOS 5.1)
  • iPad2(iOS 6)

并且它正在开发所有这些,但是在带有iOS6的iPhone 4S上,应用程序的启动大约需要20秒才能进入后台,如果你在几秒钟之后“重新启动”应用程序就会看到它仍在运行,没有任何问题。

iPhone4S(iOS6)是否有任何已知问题导致此模型或此模型有什么特别之处? [我已经在不同的iPhone4s(iOS6)上进行了测试,并且它正在所有iPhone4上进行测试]

修改

我注意到一些奇怪的东西会做更多的测试,iPhone 4s(iOS6)是唯一一个没有显示加载屏幕(第一个视图控制器),它只显示启动图像..无论如何,这里是代码对于AppDelegate和第一个视图控制器:

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    // Optional: automatically track uncaught exceptions with Google Analytics.
    [GAI sharedInstance].trackUncaughtExceptions = YES;
    // Optional: set Google Analytics dispatch interval to e.g. 20 seconds.
    [GAI sharedInstance].dispatchInterval = 20;
    // Optional: set debug to YES for extra debugging information.
    [GAI sharedInstance].debug = NO;
    // Create tracker instance.
    __unused id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-APP-ID"];
   return YES;
}

EcraPrincipalViewController.m

#import "EcraPrincipalViewController.h"
#import "ListaPercursosTableViewController.h"
#import "GlobalVars.h"
#import "AppDelegate.h"

@interface EcraPrincipalViewController ()

@end

@implementation EcraPrincipalViewController
{
    int progresso;
    int sizePercursos;
}

@synthesize lbl_versao;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.trackedViewName = @"iPhone - EcrãPrincipal";
    // Do any additional setup after loading the view.

    NSMutableArray *views = [[NSMutableArray alloc] initWithArray:[self.navigationController viewControllers]];
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"WalkMeStoryBoard" bundle:nil];
    ListaPercursosTableViewController *listaV = [story instantiateViewControllerWithIdentifier:@"view_lista"];
    [views replaceObjectAtIndex:0 withObject:listaV];
    [self.navigationController setViewControllers:views];

    lbl_info.text = NSLocalizedString(@"downloading", NULL);
    lbl_versao.text = NSLocalizedString(@"walkme_versao", NULL);

    dispatch_queue_t queue = dispatch_queue_create("com.WalkMe.downloadPercursos", NULL);
    dispatch_async(queue, ^{
        [[GlobalVars Instance] getLevadas:self];
    });
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (BOOL)shouldAutorotate
{
    return [[GlobalVars Instance] podeRodar];
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)novaAtualizacao
{
   NSLog(@"Atualização encontrada");
   lbl_info.text = NSLocalizedString(@"atualizacao_encontrada", NULL);
}
-(void)atualizarPercursosInternos
{
    NSLog(@"VERIFICAÇAO Interna");
    lbl_info.text = NSLocalizedString(@"a_atualizar_percursos", NULL);
}
-(void)setNewDownload:(NSNumber*)size
{
    NSLog(@"Iniciou VERIFICAÇAO");
    progresso = 0;
    sizePercursos = [size intValue];
    lbl_info.text = [NSString stringWithFormat:@"%@ 0/%d", NSLocalizedString(@"novos_percursos", NULL), sizePercursos];
}
-(void)setProgress
{
    NSLog(@"Progresso");
    progresso++;
    lbl_info.text = [NSString stringWithFormat:@"%@ %d/%d", NSLocalizedString(@"novos_percursos", NULL), progresso, sizePercursos];
}
-(void)goToLista
{
    NSLog(@"ACABOU VERIFICAÇAO");

    UIStoryboard *story = [UIStoryboard storyboardWithName:@"WalkMeStoryBoard" bundle:nil];
    [[GlobalVars Instance] getLevadas];
    [self.navigationController pushViewController:[story instantiateViewControllerWithIdentifier:@"view_lista"] animated:NO];
}

- (void)viewDidUnload {
    [self setLbl_versao:nil];
    [super viewDidUnload];
}
@end

非常感谢您的关注和帮助:)。

1 个答案:

答案 0 :(得分:0)

在试图弄清楚发生了什么时,对问题的评论中提出的建议让我意识到,由于某种原因,应用程序两次调用相同的方法,并且由于某种原因导致应用程序转到后台。

要解决此问题,只需从viewDidLoad

中删除此行
NSMutableArray *views = [[NSMutableArray alloc] initWithArray:[self.navigationController viewControllers]];
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"WalkMeStoryBoard" bundle:nil];
    ListaPercursosTableViewController *listaV = [story instantiateViewControllerWithIdentifier:@"view_lista"];
    [views replaceObjectAtIndex:0 withObject:listaV];
    [self.navigationController setViewControllers:views];

并将它们添加到goToLista(这在初始加载完成后调用)。

我最终得到了:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.trackedViewName = @"iPhone - EcrãPrincipal";
    // Do any additional setup after loading the view.

    lbl_info.text = NSLocalizedString(@"downloading", NULL);
    lbl_versao.text = NSLocalizedString(@"walkme_versao", NULL);

    dispatch_queue_t queue = dispatch_queue_create("com.WalkMe.downloadPercursos", NULL);
    dispatch_async(queue, ^{
        [[GlobalVars Instance] getLevadas:self];
    });
}

-(void)goToLista
{
    NSLog(@"ACABOU VERIFICAÇAO");

    [[GlobalVars Instance] getLevadas];

    NSMutableArray *views = [[NSMutableArray alloc] initWithArray:[self.navigationController viewControllers]];
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"WalkMeStoryBoard" bundle:nil];
    ListaPercursosTableViewController *listaV = [story instantiateViewControllerWithIdentifier:@"view_lista"];
    [views replaceObjectAtIndex:0 withObject:listaV];
    [self.navigationController setViewControllers:views];
    [self.navigationController pushViewController:[story instantiateViewControllerWithIdentifier:@"view_lista"] animated:NO];
}

这解决了问题,但我不知道为什么。如果有人知道请告诉我,因为我真的很想知道。

谢谢:)