ios - iOS 推送通知的位置请求(当应用程序未在后台运行时)

标签 ios notifications location push

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

相关文章:

iphone - UIbarbuttonItem 图像看起来拉伸(stretch)/变厚

ios - AFAmazonS3Manager 可接受的图像内容类型

Java返回原始数组的数组地址

ios - 多个问题(日期、天气、地点)

javascript - window.location 与位置

objective-c - 如何正确切换到横向 View ?

ios - 如何解析 JSON 响应

notifications - 构建通知系统

angularjs - 当应用程序 (UWP) 暂停时,如何接收通知并向 SignalR 中心发送通知?

javascript - 向特定用户发送浏览器通知(网络)