iPhone - 在应用程序启动期间,应用程序进入后台 [英] iPhone - During the app launch the app goes into background

查看:148
本文介绍了iPhone - 在应用程序启动期间,应用程序进入后台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Recently I have come across a problem, where my app goes into background during initial launch, but this only happens on iPhone 4S with iOS6. I have tested on:


  • 模拟器,具有不同的硬件/软件配置

  • iPhone 5(iOS 6)

  • iPhone 4S(iOS 5.1)

  • iPad2(iOS 6)

  • simulator, with different hardware/software configurations
  • iPhone 5 (iOS 6)
  • iPhone 4S (iOS 5.1)
  • iPad2 (iOS 6)

并且它正在全部工作,但在带有iOS6的iPhone 4S上,应用程序的启动需要大约20秒才能进入后台,如果你在几个之后重新启动应用程序几秒钟,你看到它仍在运行并且没有任何问题。

and it is working on all of them, but on the iPhone 4S with iOS6 the launch of the app takes about 20s before going into background, if you "re-launch" the app after a couple of seconds you see that it is still running and works without any problem.

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

Is there any know issue with iPhone4S (iOS6) that causes this or there is something special about this model? [I already tested it on different iPhone4s (iOS6) and it is happening on all of them]

编辑

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

I noticed something weird will doing some more testing, iPhone 4s (iOS6) is the only one that doesn't show the loading screen (first view controller), it only shows the launch image.. anyway, here is the code for the AppDelegate and the first view controller:

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

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

Thank you very much for your attention and help :)

推荐答案

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

While trying to figure out what was happening, the suggestions made in the comments to the question made me realize that for some reason the app was calling the same method twice and for some reason that cause the app to go to the background.

要解决此问题,只需从viewDidLoad中删除此行

To solve the problem, simply remove this lines from 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(这在初始加载完成后调用)。

and add them to goToLista (this is called after the initial loading is complete).

我最终得到:

- (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];
}

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

This solves the problem, but I don't know why. If anyone knows please do tell, because I really would like to know.

谢谢:)

这篇关于iPhone - 在应用程序启动期间,应用程序进入后台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆