これまで見てきたことはすべて、プッシュ通知アラートを自分のAppDelegate
. viewController
ただし、私のアプリでは、ユーザーが登録プロセスを実行する必要があり、登録プロセスが完了した後に表示されるにユーザーが到着しない限り、プッシュ通知を受け取りたいかどうかをユーザーに尋ねたくありません。
viewDidLoad
このコードの一部を、アプリ デリゲート以外のビュー コントローラーのメソッドに入れることはできますか? 下の 2 つのメソッド " didRegisterForRemoteNotificationsWithDeviceToken
" と " didReceiveRemoteNotification
" をアプリ デリゲートに残しておく必要がありますか? それとも、リモート通知を登録しようとしている場所に移動する必要がありますか?
以下のコード ブロックを使用して、アプリでプッシュ通知を登録しています。
アプリデリゲートの didFinishLaunchingWithOptions メソッドで:
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|
UIRemoteNotificationTypeAlert|
UIRemoteNotificationTypeSound];
アプリのデリゲートに追加されたメソッド:
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
// Store the deviceToken
}
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
//handle push notification
}
私が訪れたリソースは、このコードブロックが