On Apr 25, 2012, at 6:07 PM, Kévin Vavelin <vavelinke...@gmail.com> wrote:

> Hi there,
> 
> I've a question about the dispatch_timer function. I try to make a strobe 
> flash on my iPhone app and for that i used an NSTimer but a friend of mine 
> say that it's better to use dispatch function. So i was looking and try to 
> implement something. I explain my code before post anything :
> I have a UISlider in another view (settings.strobeValue) and get his value 
> for settings the timer. And i called changeStrobeState in another function 
> who wll be called by dispatch function. But when i hit the button on my view 
> and send my dispatch code, no work at all... So there is the code :
> 
> -(void)changeStrobeState
> {
>    if (NO == [[NSUserDefaults standardUserDefaults] 
> boolForKey:@"buttonStrobeState"])
>    {
>        [deviceCapture lockForConfiguration:nil];
>        [deviceCapture setTorchMode:AVCaptureTorchModeOff];
>        [deviceCapture unlockForConfiguration];
>    }
>    else 
>    {
>        [deviceCapture lockForConfiguration:nil];
>        [deviceCapture setTorchMode:AVCaptureTorchModeOn];
>        [deviceCapture unlockForConfiguration];
>    }
>    BOOL state = [[NSUserDefaults standardUserDefaults] 
> boolForKey:@"buttonStrobeState"];
>    [[NSUserDefaults standardUserDefaults] setBool:!state 
> forKey:@"buttonStrobeState"];
> 
> }
> 
> 
> - (dispatch_source_t)setupStrobeTimer {
>    static dispatch_once_t onceToken;
>    dispatch_once(&onceToken, ^{
>        dispatch_queue_t queue = 
> dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
>         _strobeTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 
> 0, queue);
>        if (_strobeTimer) {
>            dispatch_source_set_timer(_strobeTimer, 
> dispatch_walltime(DISPATCH_TIME_NOW, settings.strobeValue * NSEC_PER_SEC), 
>                                      settings.strobeValue * NSEC_PER_SEC, 
> 6ull * NSEC_PER_SEC);
>            __block ViewController *blockSelf = self;
>            dispatch_source_set_event_handler(_strobeTimer, ^{
>                [blockSelf changeStrobeState];
>            });

Kévin,

Your code is not calling dispatch_resume() on the timer source. Please review 
the man page and/or other documentation.

davez

>        }
>    });
>    return _strobeTimer;
> }
> 
> Can you help me ?
> 
> Thanks for reading and sorry 'cause my english is not perfect and it's 
> actually 3 AM here :)
> 
> Cheers,
> Vavelin Kevin
> Twitter | Blog | Viadeo
> 
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/zarzycki%40apple.com
> 
> This email sent to zarzy...@apple.com


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to