当应用程序未在后台运行时,是否可以发送 iOS 推送通知来获取位置?就像“查找我的 iPhone”一样......
最佳答案
UIRemoteNotification是你的 friend 。
1) 注册您的应用以进行远程推送通知:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound];
2) 实现 applicationDidFinishLaunching 上的逻辑(以处理应用程序关闭时到达的推送通知)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//...
if([launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) {
//if we're here, apps was launched due to Remote Notification
}
//...
}
3) 在 didReceiveRemoteNotification 上实现登录(以处理应用程序在前台运行时到达的推送通知)
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
//...
//business logic for GPS Position
//...
}
在步骤 2 和 3 中,实现您的业务逻辑以获取实际的 GPS 位置。
有关 Apple 开发者文档的更多信息:http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008194-CH1-SW1
关于ios - iOS 推送通知的位置请求(当应用程序未在后台运行时),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8979878/