Question

lire beaucoup de choses sur la façon de prévenir le sommeil iphone goingto lors de l'exécution de mon application, je suis très malheureux pour le moment car rien ne fonctionnait ..

je lis sur l'idée de mettre en place une minuterie pour toutes les 30 secondes pour régler le idleTimerDisabled NO et YES, mais mon objc est pas encore bonne. Quelqu'un pourrait me dire comment (et où)?

thnx!

modifier: voici le code que j'ai essayé:

- (void)applicationDidFinishLaunching:(UIApplication *)application
{   
    [ super applicationDidFinishLaunching:application ];
    //application.idleTimerDisabled = NO;
    //application.idleTimerDisabled = YES;
    //[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
    [UIApplication sharedApplication].idleTimerDisabled = NO;
    [UIApplication sharedApplication].idleTimerDisabled = YES;


}

Edit2: après que j'ai essayé de démarrer une boucle avec:

-(void)_timerLoop
{
    // add this function up the top.  it's what will happen when the
    // timer goes off:
    NSLog(@"Your timer went off!!!");
}


/**
 * This is main kick off after the app inits, the views and Settings are setup here.
 */
- (void)applicationDidFinishLaunching:(UIApplication *)application
{   
    [ super applicationDidFinishLaunching:application ];
    //application.idleTimerDisabled = NO;
    //application.idleTimerDisabled = YES;
    //[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
    //[UIApplication sharedApplication].idleTimerDisabled = NO;
    //[UIApplication sharedApplication].idleTimerDisabled = YES;
    [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(_timerLoop) userInfo:nil repeats:YES];


}

EDIT3: on ne peut pas changer accidentially downvotes? serait une belle demande de chnage au système stackoverflow!

Était-ce utile?

La solution

En ce qui concerne votre question sur l'utilisation d'une minuterie :

Voici comment vous faites une minuterie se déclenche (juste une fois) en 30 secondes à partir de maintenant:

-(void)_jump
{
// add this function up the top.  it's what will happen when the
// timer goes off:
NSLog(@"Your timer went off!!!");
}
...
// here's how to create the timer, which will go off in 30 seconds
[NSTimer scheduledTimerWithTimeInterval:30.0
   target:self selector:@selector(_jump) userInfo:nil repeats:NO]

Si vous voulez deux minuteries différentes , par exemple au bout de 30, puis 60 secondes, il suffit de faire deux de la même manière. Faites-moi savoir si vous avez besoin de plus d'aide avec des minuteries!


Il ne pouvait pas être plus facile. Il suffit d'ajouter cette ligne:

application.idleTimerDisabled = YES;

Dans votre routine "application didFinishLaunchingWithOptions".

Vous trouverez cette routine dans votre délégué app fichier de code source .m.

Assurez-vous d'ajouter AVANT "OUI retour;" déclaration - une erreur commune! Alors, exactement comme ceci:

-(BOOL)application:(UIApplication *)application
            didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    // blah blah ...

    application.idleTimerDisabled = YES;
    return YES;
    }

Autres conseils

Juste paramètre [UIApplication sharedApplication] .idleTimerDisabled = OUI; en

  • (BOOL) application: (*) UIApplication l'application didFinishLaunchingWithOptions: (*) NSDictionary launchOptions

fonctionne bien pour moi. Cependant, il y a une mise en garde. J'ai remarqué que tous les temps I Invoke utilitaire appareil photo de mon application PhoneGap pour prendre un instantané, idleTimerDisable se prépare à NO derrière la scène. Donc, juste après je télécharger mon image, je devais appeler à nouveau la ligne de code suivante:

[UIApplication sharedApplication] .idleTimerDisabled = OUI;

En outre, je ne serais pas surpris s'il y a plus d'endroits à travers le ralenti app timer obtient réactivée.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top