2011-07-15 20 views
0

林與計時器創建應用程序,並顯示彈出窗口埃夫裏30秒如何顯示UIAlertvew然後applicacation在後臺運行

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

[window addSubview:viewController.view]; 
[window makeKeyAndVisible]; 



timer = [NSTimer scheduledTimerWithTimeInterval:(30) 
             target:self 
             selector:@selector(showpopup:) 
             userInfo:nil 
             repeats:YES]; 




} 

-(void) showpopup:(NSTimer *)theTimer{ 

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"YAHooo!" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert show]; 
     [alert release]; 

} 

如何改變代碼顯示在後臺模式彈出窗口

回答

2

無法顯示UIAlertView當你的應用程序在後臺。您可以使用UIAlertView格式的UILocalNotification,但每個應用程序的通知數量都有限制。要安排UILocalNotification,請按照tutorial

+0

Thnx它可以幫助我) – Ruslan

+0

你能幫我添加NSTimer和UILocalNotification來添加appdelegate文件來每隔30秒顯示一次嗎? – Ruslan

+0

當您在後臺時,NSTimer將無法工作,除非您開始後臺任務。請參閱http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html –