Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何延迟抖动通知_Iphone_Objective C_Xcode_Xcode4 - Fatal编程技术网

Iphone 如何延迟抖动通知

Iphone 如何延迟抖动通知,iphone,objective-c,xcode,xcode4,Iphone,Objective C,Xcode,Xcode4,我想将抖动延迟5秒,因为如果用户持续抖动设备,响应将显示为null。这就是为什么我想延迟震动直到n,除非响应是活动的 这是我的密码 - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (motion == UIEventSubtypeMotionShake) { [FlurryAnalytics logEvent:@"User shaked to update"];

我想将抖动延迟5秒,因为如果用户持续抖动设备,响应将显示为null。这就是为什么我想延迟震动直到n,除非响应是活动的

这是我的密码

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {

    if (motion == UIEventSubtypeMotionShake) {

        [FlurryAnalytics logEvent:@"User shaked to update"];

        [[NSNotificationCenter defaultCenter] postNotificationName:@"CheckWeather" object:nil];

        [[NSNotificationCenter defaultCenter] postNotificationName:@"startWeatherNeue" object:nil];

        if ( [super respondsToSelector:@selector(motionEnded:withEvent:)] )

            [super motionEnded:motion withEvent:event];

    }
}

要在以后执行某些选择器,可以使用:

- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay

在目标c中,我使用睡眠(6)停止处理, 将睡眠(6)置于您的已触发通知代码之前:-

-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {

if (motion == UIEventSubtypeMotionShake) {

 sleep(6);

[FlurryAnalytics logEvent:@"User shaked to update"];

[[NSNotificationCenter defaultCenter] postNotificationName:@"CheckWeather" object:nil];

[[NSNotificationCenter defaultCenter] postNotificationName:@"startWeatherNeue" object:nil];

if ( [super respondsToSelector:@selector(motionEnded:withEvent:)] )

    [super motionEnded:motion withEvent:event];

    } 
 }
然后进程停止6秒钟,然后在6秒钟后通知fire可能会对您有所帮助

其他

u还使用NSTimer:-

在NSTimer u中,在if-else条件下检查响应数组计数>0,并在响应数组>0时用1秒调用方法,然后调用NSNOtification方法

下面是我的示例:-使用NSTimer

  -(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event 
 {

  self.TimeOfActiveUser = [NSTimer scheduledTimerWithTimeInterval:01.0  target:self   selector:@selector(checkInfoString) userInfo:nil repeats:YES];
 }


 -(IBAction)checkInfoString
 {

    if([responsearray count]>0)
    {
    [FlurryAnalytics logEvent:@"User shaked to update"];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"CheckWeather" object:nil];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"startWeatherNeue" object:nil];

        if ( [super respondsToSelector:@selector(motionEnded:withEvent:)] )
        {
          [super motionEnded:motion withEvent:event];
         } 

    }
   else
    {

     NSLOG
    }
 }

谢谢你,尼廷,我会在我的需求中检查这段代码,看看它是如何工作的!!