当应用程序不在后台运行时,是否可以发送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/