无法在iPhone应用程序中运行后台操作
我已仔细阅读过苹果开发用户指南重新执行多任务操作,但我仍无法理解如何在后台运行简单操作。我做了以下简单的实验,但什么都没有发生:无法在iPhone应用程序中运行后台操作
- (void)applicationDidEnterBackground:(UIApplication *)application
{
sleep(3);
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"title" message:@"test" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil , nil];
[alert1 show];
}
所以我的理解是增加了对音频/位置/ VoIP的业务支持,同时在后台默认情况下给出的,但我怎么可以添加这样一个简单的操作支持?
非常感谢您的帮助。
我希望这个答案。是你的问题非常有用
当关闭应用程序比你可以在后台看到AlertView消息..
- (void)viewDidLoad
{
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate =[NSDate dateWithTimeIntervalSinceNow:15];
localNotif.timeZone = [NSTimeZone localTimeZone];
localNotif.alertBody = @"Staff meeting in 30 minutes";
//localNotif.alertBody = [NSString stringWithFormat:@"%@'s Birthday",strName];
localNotif.alertAction = @"View";
localNotif.soundName = UILocalNotificationDefaultSoundName;
// localNotif.applicationIconBadgeNumber = 1;
localNotif.repeatInterval = NSYearCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
您试图在应用程序进入后台时显示警报。尝试使用NSLog打印某些东西或放置一个断点并检查控制是否采用此方法。
它使用的NSLog的时候,但我想测试它没有模拟器不工作。 ..我可以做到这一点? – moshikafya 2012-07-25 03:06:28
你可以进入主屏幕在sim上进行测试。 – 2012-07-25 03:12:09
不知道我明白你的意思吗?我想在设备未连接到Xcode的情况下在“真实生活”中进行测试。知道我的应用程序确实在后台运行的最佳方式是什么? – moshikafya 2012-07-25 03:22:31
你的应用在后台无法做任何UI东西。你可以做其他的工作,比如获取数据或者在后台处理一些数据。 要启用audio/location/voip,您需要正确设置info.plist以启用该功能。 应该记录在iOS文档中
感谢,但将我重定向到文档并没有帮助...正如我所提到的,我已经完成了它们。 – moshikafya 2012-07-25 03:07:55
谢谢@jaydeep,但我的问题是更一般的如何处理后台操作,不一定提醒视图。警报视图只是一个视觉方式,让我知道该应用程序确实在后台工作。 – moshikafya 2012-07-25 10:54:02