我问我是否可以在按下主页按钮后重复Xcode 中的方法。我们每隔30分钟说一次。
如果有可能,我不知道如何做。
答案 0 :(得分:1)
我认为您的问题与后台执行有关,方法是在按下主页按钮后 。首先,您需要解决如何在后台调用该函数。
以下是我建议您遵循的内容:
<强>首先强>
我建议你看看苹果官方文件。
<强>第二强>
有一个很好的教程:
<强>第三强>
以下是您的要求:
<强>第四:强>
如果您想探索高级材料:
答案 1 :(得分:0)
使用 NSTimer
[NSTimer scheduledTimerWithTimeInterval:"your time"
target:self
selector:@selector(your method:)
userInfo:nil
repeats:YES];
答案 2 :(得分:0)
有些方法(例如&#34; viewDidLoad&#34;)会针对这些情况进行调用。以下是一些:
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
当按下主页按钮时,您可以将NSTimer放入其中一个以及您想要执行的任何其他操作。希望这会有所帮助。