2

我找到了一些关于 PNS 的示例代码,文章在这里

我还创建了一个 UISwitch 来启用 PNS

如何给出控制 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]];
 }
} 

现在我只是使用单元格的文本标签颜色更改来表示开关调用方法

所以...我可以用它来控制 PNS 的启用与否???

感谢您的任何评论和回答!

4

2 回答 2

5

要使以下所有工作正常进行,您应该已向 Apple 注册推送通知服务作为通知提供程序。

根据用户对 Switch 控制输入的选择,可以调用

取消注册远程通知

或者

registerForRemoteNotificationTypes

.

如果用户想从通知中注销,可以通过调用unregisterForRemoteNotifications方法来实现。

再次,如果您想注册通知,您可以在 Application 对象上使用 registerForRemoteNotificationTypes 方法。

有关更多信息,您可以参考此链接

更新:

你可以这样称呼它:

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

[[UIApplication sharedApplication] unregisterForRemoteNotifications];

您可以使用我提到的链接获取更多信息。

于 2010-10-06T12:17:59.543 回答
2

您可以使用 为您的应用程序激活 PNSregisterForRemoteNotificationTypes:或使用 取消激活它unregisterForRemoteNotifications。请参阅http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/instm/UIApplication/registerForRemoteNotificationTypes:了解更多信息:

于 2010-10-06T12:03:21.160 回答