Swift - 查找在

时间:2015-08-02 05:47:11

标签: php ios swift gps

需要一些逻辑方面的帮助。我将应用程序启动时将我的应用程序用户的位置信息(lat,long)存储在数据库中(并在应用程序正在使用时定期更新)。

我的应用程序的主要功能是查找当前正在运行该应用程序的附近用户。

仅在邻近范围内查询数据库中的“附近用户”是不够的,因为我还需要它们来运行应用程序。

我不确定如何“知道”用户运行应用的时间与5分钟前使用我的应用的用户(记录其lat / lng)然后关闭应用。

看到类似的问题(特定于Android),但没有真正触及“活跃”用户。

(目前用Swift编写,PHP作为我的服务器端语言)

1 个答案:

答案 0 :(得分:0)

您可以在AppDelegate中使用以下方法来管理状态,然后根据状态更改执行查询或删除用户是否有资格被查找。

func applicationWillResignActive(application: UIApplication) {
    // 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.
}

func applicationDidEnterBackground(application: UIApplication) {
    // 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.
}

func applicationWillEnterForeground(application: UIApplication) {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    // Saves changes in the application's managed object context before the application terminates.

}