2

PNSに関するサンプルコードをいくつか見つけました。記事はこちら

また、PNSを有効にするUISwitchを作成します

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に登録しておく必要があります。

スイッチコントロールからのユーザーの入力の選択に応じて、あなたは呼び出すことができます

unregisterForRemoteNotifications

また

registerForRemoteNotificationTypes

ユーザーが通知から登録を解除したい場合は、unregisterForRemoteNotificationsメソッドを呼び出すことでこれが可能です。

もう一度、通知に登録する場合は、ApplicationオブジェクトでregisterForRemoteNotificationTypesメソッドを使用できます。

詳細については、このリンクを参照してください。

アップデート:

あなたはそれをこのように呼ぶことができます:

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

[[UIApplication sharedApplication] unregisterForRemoteNotifications];

詳細については、私が参照したリンクを使用できます。

于 2010-10-06T12:17:59.543 に答える
2

アプリのPNSは、でregisterForRemoteNotificationTypes:アクティブ化することも、で非アクティブ化することもできます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 に答える