iPhone - 在应用程序启动的应用程序进入后台(iPhone - During the app

2019-10-17 10:23发布

最近,我所遇到的一个问题,在我的应用程序首次启动时进入的背景,但是这只是发生在iPhone 4S的使用iOS6的。 我已经测试了:

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

它正在所有的人,但与iOS6的iPhone 4S的推出的应用程序大约需要20秒才能进入的背景下,如果你看到它仍在运行“重新启动”几秒钟后,该应用程序与工作没有任何问题。

有没有用的iPhone4S(iOS6的)任何已知问题导致此还是有一些特别之处这种模式? [I已经测试了不同的iPhone4s(iOS6的),它是发生在所有这些]

编辑

我发现了一些奇怪的意愿做一些更多的测试,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

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

Answer 1:

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.

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

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

I ended up with:

- (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.

Thank you :)



文章来源: iPhone - During the app launch the app goes into background