uriel
uriel

Reputation: 1248

location request by iOS push notification (when the application is NOT running on backgorund)

is it possible to send iOS push notification to get location when the application is not running in background? exactly as Find My iPhone do it..

Upvotes: 2

Views: 2823

Answers (3)

Sonny Saluja
Sonny Saluja

Reputation: 7287

When the app is running in the background, the only thing it can do with a push notification is to show a numeric badge, play a pre-packaged sound and/or display an alert. There is no code in your application that can be executed when the device receives push and your app is in the background.

Upvotes: 0

valvoline
valvoline

Reputation: 8117

UIRemoteNotification is your friend.

1) Register your app for Remote Push Notification:

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

2) Implement the logic on applicationDidFinishLaunching (to handle push notifications arriving when the app is closed)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //...

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

    }

    //...
}

3) Implement the login on didReceiveRemoteNotification (to handle push notifications arriving when the app is running in foreground)

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    //...
    //business logic for GPS Position    
    //...
}

On step 2 and 3, implement your business logic to get the actual GPS position.

More info here on Apple Developer Documentation: http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008194-CH1-SW1

Upvotes: 4

ACBurk
ACBurk

Reputation: 4428

No, it's not. Sorry. You can send a push notification requesting the user open the app and then the app can start getting their location.

Upvotes: -1

Related Questions