关于推送通知

时间:2011-04-08 08:23:08

标签: iphone push-notification

我正在开发一个应用程序,当我从该位置说x米时,我需要向用户提供通知。我已经实现了地图,所有这些的逻辑。现在我想实现推送通知在那里。我已经在这里看到堆栈溢出但没有找到解决方案。我知道我需要在app delegate中提供方法。但我想知道我的服务器将如何知道用户是x我还需要解析web服务并在didupdatetoUserLocation.Or中发送数据,服务器将负责处理。如果服务器那将是服务器将如何知道。 任何帮助,将不胜感激 谢谢大家......

1 个答案:

答案 0 :(得分:2)

您必须将所有位置信息发送到您的服务器,并且您的服务器必须计算推送服务是否变为活动状态。如果应用程序在后台处于活动状态并且会导致大量通信堆栈,那就可以了。

我建议使用本地推送服务。通过在设备后台调用函数,您可以跟踪位置并将其与“推送”位置进行比较。如果要显示推送,请继续使用自iOS 4以来可用的UILocalNotification: 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];

由于您需要基于服务器的推送服务,请在您的appdelegates方法applicationDidFinishLaunching中实现以下方法,这就是如何为服务注册设备:

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

此外,您可以实施以下方法进行详细设置:

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

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

由于我不熟悉基于服务器的推送通知,我不能告诉你更多,我所知道的是,你需要设置一个带有密钥的服务器,你在服务中生成并注册了苹果简介: http://developer.apple.com/ios/manage/bundles/index.action