在目标 ci 中使用sleep(6)停止处理,将 sleep(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 秒后触发通知可能对您有帮助
其他
你也使用 NSTimer :-
在 NSTimer 中,您在 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
}
}