は
VApplication.h
#import <Foundation/Foundation.h>
// # of minutes before application times out
#define kApplicationTimeoutInMinutes 10
// Notification that gets sent when the timeout occurs
#define kApplicationDidTimeoutNotification @"ApplicationDidTimeout"
/**
* This is a subclass of UIApplication with the sendEvent: method
* overridden in order to catch all touch events.
*/
@interface VApplication : UIApplication
{
NSTimer *_idleTimer;
}
/**
* Resets the idle timer to its initial state. This method gets called
* every time there is a touch on the screen. It should also be called
* when the user correctly enters their pin to access the application.
*/
- (void)resetIdleTimer;
@end
VApplication対応するクラスに、これらのコードのUIApplication から延びるクラス "VApplication" を作成して貼り付け。メートル
#import "VApplication.h"
#import "AppDelegate.h"
@implementation VApplication
- (void)sendEvent:(UIEvent *)event
{
[super sendEvent:event];
// Fire up the timer upon first event
if(!_idleTimer) {
[self resetIdleTimer];
}
// Check to see if there was a touch event
NSSet *allTouches = [event allTouches];
if ([allTouches count] > 0)
{
UITouchPhase phase = ((UITouch *)[allTouches anyObject]).phase;
if (phase == UITouchPhaseBegan)
{
[self resetIdleTimer];
}
}
}
- (void)resetIdleTimer
{
if (_idleTimer)
{
[_idleTimer invalidate];
}
// Schedule a timer to fire in kApplicationTimeoutInMinutes * 60
// int timeout = [AppDelegate getInstance].m_iInactivityTime;
int timeout = 3;
_idleTimer = [NSTimer scheduledTimerWithTimeInterval:timeout
target:self
selector:@selector(idleTimerExceeded)
userInfo:nil
repeats:NO];
}
- (void)idleTimerExceeded
{
/* Post a notification so anyone who subscribes to it can be notified when
* the application times out */
[[NSNotificationCenter defaultCenter]
postNotificationName:kApplicationDidTimeoutNotification object:nil];
}
@end
当社
にクラス名 "VApplication" を置き換えMain.m
が
この
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, @"VApplication", NSStringFromClass([AppDelegate class]));
}
}
のようなファイルは、対応するための通知を登録しますビューコントローラ
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidTimeout:) name:kApplicationDidTimeoutNotification object:nil];
、タイムアウト一度通知は、こののダウンサイズは、我々は、実行時にこれを行うことができないということである。この
- (void) applicationDidTimeout:(NSNotification *) notif //inactivity lead to any progress
{
}
のようなイベントが発生し、処理しますが発生。その他の回避策? – Legoless
どのようにそれがあったかを理解する方法? –
@AsadullahAli 'UIEvent'のドキュメント(https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIEvent_Class/index.html)を参照してください。すべてのイベントには、タイプ、サブタイプ、および検査可能な一連のタッチがあります。 – Sulthan