2010-10-04 11 views
26

Bir uygulamanın "arka plan modu" ndan yeni döndüğünü nasıl anlayabilirim? Yani, kullanıcı "ana düğme" düğmesine bastığında uygulamamın verileri (60 saniyede bir) almasını istemiyorum. Ancak, uygulamanın ön plan modunda olduğu ilk seferde bazı "özel" güncellemeyi yapmak istiyorum.iphone 4 sdk: arka plan modundan dönüş algılandı

nasıl bu iki etkinliği tespit edebilir:

  1. uygulama önceden ön plan moduna

Teşekkür gidiş

  • uygulama arka plan modunda gidiyor.

    // Register for notification when the app shuts down 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myFunc) name:UIApplicationWillTerminateNotification object:nil]; 
    
    // On iOS 4.0+ only, listen for background notification 
    if(&UIApplicationDidEnterBackgroundNotification != nil) 
    { 
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myFunc) name:UIApplicationDidEnterBackgroundNotification object:nil]; 
    } 
    
    // On iOS 4.0+ only, listen for foreground notification 
    if(&UIApplicationWillEnterForegroundNotification != nil) 
    { 
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myFunc) name:UIApplicationWillEnterForegroundNotification object:nil]; 
    } 
    

    Not:

    François

  • cevap

    48

    İşte böyle olayları dinlemek için nasıl if(&SomeSymbol) çek kodunuzu iOS'taki 4.0+ ve iOS 3.x üzerinde çalışacak sağlamak - Eğer inşa halinde iOS 4.x veya 5.x SDK'ya karşı ve iOS 3.x'e dağıtım hedefini ayarladığınızda uygulamanız yine de 3.x cihazlarda çalışabilir, ancak ilgili sembollerin adresi sıfır olacaktır ve bu nedenle sormaya çalışmaz 3.x cihazlarda bulunmayan bildirimler için (uygulamayı kilitler).

    Güncelleme: Bu durumda, if(&Symbol) kontroller artık gereksizdir (eğer gerçekten nedense iOS 3 desteklemesi gerektiğini sürece). Bununla birlikte, bir tekniğin kullanmadan önce var olup olmadığını kontrol etmek için bu tekniği bilmek yararlıdır. Bu tekniği, işletim sistemi sürümünü test etmekten daha çok tercih ediyorum çünkü belirli API sürümlerinin hangi işletim sistemlerinde hangi API'ların var olduğuna dair bilgi kullanmak yerine mevcut olup olmadığını kontrol ediyorsunuz. Eğer bir UIApplicationDelegate uygularsanız

    +0

    teşekkür bakın! –

    5

    , ayrıca temsilci bir parçası olarak fonksiyonları içine kanca: protokol Başvuru için

    - (void)applicationDidEnterBackground:(UIApplication *)application { 
        /* 
        Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    If your application supports background execution, called instead of applicationWillTerminate: when the user quits. 
        */ 
        NSLog(@"Application moving to background"); 
    } 
    
    
    - (void)applicationWillEnterForeground:(UIApplication *)application { 
        /* 
        Called as part of the transition from the background to the active state: here you can undo many of the changes made on entering the background. 
        */ 
        NSLog(@"Application going active"); 
    } 
    

    hızlı cevap için http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html

    İlgili konular