2011-07-15 21 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 –