OGeek|极客世界-中国程序员成长平台

标题: ios - iOS推送通知的位置请求(当应用程序不在后台运行时) [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 10:58
标题: ios - iOS推送通知的位置请求(当应用程序不在后台运行时)

当应用程序不在后台运行时,是否可以发送 iOS 推送通知来获取位置?就像查找我的 iPhone 一样..



Best Answer-推荐答案


UIRemoteNotification 是你的 friend 。

1) 为您的应用注册远程推送通知:

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:  UIRemoteNotificationTypeAlert |
                                                                        UIRemoteNotificationTypeBadge |
                                                                        UIRemoteNotificationTypeSound];

2) 在 applicationDidFinishLaunching 上实现逻辑(处理应用关闭时到达的推送通知)

- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions
{
    //...

    if([launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) {
        //if we're here, apps was launched due to Remote Notification

    }

    //...
}

3) 在 didReceiveRemoteNotification 上实现登录(处理应用在前台运行时到达的推送通知)

- (void)applicationUIApplication *)application didReceiveRemoteNotificationNSDictionary *)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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4