Sabby
Sabby

Reputation: 2592

About Push Notification

I am developing an app ,where I need to provide the notification to the user, when he is say x meter from the location.I have implemented the map,the logic for all that.Now I want to implement the push notification in that.I have read here on the stack overflow but didn't find the solution.I knew that I need to provide the methods in the app delegate.But i want to know how my server will come to know that the user is x meters from the destination.Do I also need to parse the webservice and send the data in the didupdatetoUserLocation.Or the server will take care of that.If server would that then how the server will come to know. Any help would be appreciated Thanks All......

Upvotes: 0

Views: 178

Answers (1)

Lepidopteron
Lepidopteron

Reputation: 6165

you would have to send all the location-information to your server and your server would have to calculate, whether the push service shall become active or not. That would just work, if the application is active in the background and would cause a lot of communication stack.

I would suggest to use the local push service. By calling a function in the background on the device you can track the location and compare it to the "push"-location. If the push shall be shown, continue with UILocalNotification which is available since iOS 4: http://developer.apple.com/library/ios/#documentation/iphone/Reference/UILocalNotification_Class/Reference/Reference.html

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
{
    return;
}
localNotif.fireDate = [NSDate date];
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = [NSString stringWithFormat:NSLocalizedString(@"Hey there, you are here: %@\n%@", nil), @"Country", @"Town"];
localNotif.alertAction = NSLocalizedString(@"W00t show me", nil);

localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;

NSDictionary *infoDict = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1344] forKey:@"LocationPush"];
localNotif.userInfo = infoDict;

[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];

Since you need a server based push service, implement the following methods in your appdelegates method applicationDidFinishLaunching, thats how you can register the device for the service:

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

Further on you can implement the following methods for detailed settings:

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{ 
}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
{ 
}

Since I'm not that familiar with server-based push notification I can't tell you more, all I know about is, that you need to set up a server with the key, that you generated and registered in the provision profile of apple: http://developer.apple.com/ios/manage/bundles/index.action

Upvotes: 2

Related Questions