iPhone的SDK:是否可以使用UISwitch启用和禁用PNS(推送通知服务)? [英] Iphone Sdk:Is it possible to use an UISwitch to enable and disable PNS(Push Notification Service)?

查看:424
本文介绍了iPhone的SDK:是否可以使用UISwitch启用和禁用PNS(推送通知服务)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一些样品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

unregisterForRemoteNotifications

registerForRemoteNotificationTypes

registerForRemoteNotificationTypes

如果用户希望从通知注销,这是有可能通过调用<一个href=\"http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html%23//apple_ref/occ/instm/UIApplication/unregisterForRemoteNotifications\">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(推送通知服务)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆