Ce forum est en partie financé par l’affichage de publicités. Merci de désactiver votre bloqueur de publicités pour nous permettre de continuer à fournir ce service.

Run Application in background

Discussion dans 'Développement iOS' créé par Jennniferpeters, 30 Janvier 2016.

  1. Jennniferpeters

    Jennniferpeters Nouveau membre

    Inscrit:
    30 Janvier 2016
    Messages:
    1
    J'aime reçus:
    0
    I want to be alerted when the battery level has changed. I can get the device level. Everything is ok so far. The problem is what do I do to keep themselves notified when the application is running in the background? I arrived "external accessory communication" in the section on capacities in Xcode. Will it be enough to get notified when the battery level changed if the application is in the background?

    Code (Text):
     (void) viewDidLoad {

       
        [super viewDidLoad];
       
        [[UIDevice currentDevice] setBatteryMonitoringEnabled: YES];
        [[NSNotificationCenter defaultCenter] addObserver: self selector:selector (batteryChanged :) name: UIDeviceBatteryLevelDidChangeNotification object: nil];
        [[NSNotificationCenter defaultCenter] addObserver: self selector:selector (batteryChanged :) name: UIApplicationDidEnterBackgroundNotification object: nil];
    }
    - (Void) batteryChanged (NSNotification *) notification {
        * UIApplication application = [UIApplication sharedApplication];
       
        if ([[UIDevice currentDevice] respondsToSelector:selector (isMultitaskingSupported)])
        {
            NSLog (@ "; Multitasking Supported");
           
            __block UIBackgroundTaskIdentifier background_task;
         
            background_task = [beginBackgroundTaskWithExpirationHandler app: ^ {
                background_task = UIBackgroundTaskInvalid;
            }];
           
            UIDevice MyDevice * = [UIDevice currentDevice];
            [MyDevice setBatteryMonitoringEnabled: YES];
            int state = [MyDevice batteryState];
            batLeft int = (float) [MyDevice BatteryLevel] * 100;
           
    // If (batLeft <68) {
    //          
    // [PlaySoundFile self];
    } //
           
            [self playSoundFile];
           
            NSLog (@ "; beginBG called");
           
            [endBackgroundTask app: background_task];
    }
     
Chargement...

iOccasion - Achetez un produit Apple d'occasion

refurb Apple