Web*_*Lai 2 iphone sdk push-notification apple-push-notifications uiswitch
我在这里找到一些关于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]];
}
}
Run Code Online (Sandbox Code Playgroud)
现在我只是使用单元格的文本标签颜色更改来表示交换机调用该方法
所以...我可以用它来控制PNS启用与否???
感谢您的任何意见和解答!
要使以下所有工作正常,您应该已在Apple注册推送通知服务作为通知提供程序.
根据用户对Switch控制输入的选择,您可以拨打电话
unregisterForRemoteNotifications
要么
registerForRemoteNotificationTypes
.
如果用户想要从Notification中取消注册,则可以通过调用unregisterForRemoteNotifications方法来实现.
如果要注册通知,可以再次在Application对象上使用registerForRemoteNotificationTypes方法.
有关详细信息,请参阅此链接.
更新:
你可以这样称呼它:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
Run Code Online (Sandbox Code Playgroud)
您可以使用我提到的链接获取更多信息.
归档时间: |
|
查看次数: |
2592 次 |
最近记录: |