问题描述
我找到了一些样品code约PNS,<一个href=\"http://stackoverflow.com/questions/1052645/apple-pns-push-notification-services-sample-$c$c\">article这里
I find some sample code about PNS,article here
我也创建一个UISwitch使PNS
and I also create an UISwitch to enable PNS
如何给控制PNS的方法?
how to give a method to control the PNS ?
这是我如何声明细胞
cell.textLabel.text = @"PNS";
[cell.textLabel setTextColor:[UIColor grayColor]];
pushNotificationSwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
[cell addSubview:pushNotificationSwitch];
cell.accessoryView = pushNotificationSwitch;
[(UISwitch *)cell.accessoryView addTarget:self action:@selector(pushNotification:) forControlEvents:UIControlEventValueChanged];
}
- (void)pushNotification:(id)sender{
if (pushNotificationSwitch.on==YES) {
UITableViewCell *cell = (UITableViewCell*)pushNotificationSwitch.superview;
[cell.textLabel setTextColor:[UIColor blackColor]];
}
else {
UITableViewCell *cell = (UITableViewCell*)pushNotificationSwitch.superview;
[cell.textLabel setTextColor:[UIColor grayColor]];
}
}
现在我只用一个单元格的文本标签颜色的变化来重新presentation开关调用方法
now I'm just use a cell's text label color change to representation the switch is call the method
所以...我可以用它来控制PNS启用或不???
SO... can I use it to control PNS enable or not ???
感谢您的任何意见和解答!
Thanks for any comments and answers !
推荐答案
对于以下所有的工作,你应该已经与苹果注册了推送通知服务作为一个通知提供商。
For all the following to work, you should have registered with Apple for Push notification services as a Notification provider.
据切换控制用户的选择输入,你可以叫
According to user's choice of input from Switch control, you can call
unregisterForRemoteNotifications
或
registerForRemoteNotificationTypes
如果用户希望从通知注销,这是有可能通过调用unregisterForRemoteNotifications方法。
If user wants to unregister from Notification, this is possible by invoking unregisterForRemoteNotifications method.
再次,如果你想为注册通知,您可以在应用程序对象上使用registerForRemoteNotificationTypes方法。
Once again if you wanted to register for the notification, you can use registerForRemoteNotificationTypes method on your Application object.
有关更多信息,你可以参考此。
For more info you can refer this link.
更新:
您可以把它这种方式:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
您可以使用的链接我所提到的更多信息。
You can use the links I have referred for more info.
这篇关于iPhone的SDK:是否可以使用UISwitch启用和禁用PNS(推送通知服务)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!