Question

I find some sample code about PNS,article here

and I also create an UISwitch to enable PNS

how to give a method to control the PNS ?

This is how I declare cell

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]];
 }
} 

now I'm just use a cell's text label color change to representation the switch is call the method

SO... can I use it to control PNS enable or not ???

Thanks for any comments and answers !

Was it helpful?

Solution

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

or

registerForRemoteNotificationTypes

.

If user wants to unregister from Notification, this is possible by invoking unregisterForRemoteNotifications method.

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.

UPDATE:

You can call it this way:

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

[[UIApplication sharedApplication] unregisterForRemoteNotifications];

You can use the links I have referred for more info.

OTHER TIPS

You can activate the PNS for your app with registerForRemoteNotificationTypes: or deactivate it with unregisterForRemoteNotifications. See http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/instm/UIApplication/registerForRemoteNotificationTypes: for more information:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top