我已经研究并实现了ray这些关于apns的精彩教程 http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12 http://www.raywenderlich.com/3525/apple-push-notification-services-tutorial-part-2
他们甚至在生产模式下工作得很好我实现了它们,现在我想在应用程序处于前台(运行)而不是气泡时显示警报类型通知,所以我做了我使用nsnotification,我在里面发布通知 addMessageFromRemoteNotification:(NSDictionary *)userInfo updateUI:(BOOL)这样的updateUI方法NSMutableArray* parts = [NSMutableArray arrayWithArray:[alertValue componentsSeparatedByString:@": "]];
message.senderName = [parts objectAtIndex:0];
[parts removeObjectAtIndex:0];
message.text = [parts componentsJoinedByString:@": "];
int index = [dataModel addMessage:message];
[MySingleton sharedMySingleton].Msender = message.senderName;
[MySingleton sharedMySingleton].Mtext = message.text;
[[NSNotificationCenter defaultCenter] postNotificationName:@"Notificationreceived" object:nil];
然后我在登录视图控制器中添加了观察者,如此
- (void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(responseFromServer) name:@"TokenRecieved" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(displaynotif) name:@"Notificationreceived" object:nil];
[super viewWillAppear:animated];
}
和
-(void)displaynotif
{
NSString *msgsender = [MySingleton sharedMySingleton].Msender;
NSString *msgtext = [MySingleton sharedMySingleton].Mtext;
NSString *Compmsg = [NSString stringWithFormat:@"%@ %@", msgsender, msgtext];
UIAlertView * view=[[UIAlertView alloc] initWithTitle:@"Alert" message:Compmsg delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[view show];
[view release];
}
现在我有一个问题,当第一次通知出现时它只显示一次,但是当第二次出现时它显示两次(相同的通知),第三次出现三次等等,我使用这个PHP脚本服务器端和通知是通过php Web表单从服务器端发送
https://github.com/sebastianborggrewe/PHP-Apple-Push-Notification-Server 我也在dealloc中删除观察者。 我无法弄清楚发生了什么,PLZ。指导thanx
答案 0 :(得分:1)
您必须更深入地调试进行实际连接的框架,以查看服务器响应或至少SSL连接异常,但我的猜测是您已过期证书 - 它们不会持续太多