[解決済み] ios8ではdidRegisterForRemoteNotificationsWithDeviceTokenは呼ばれないが、didRegister...Settingsは呼ばれる。
質問
私は
このスレッド
しかし、その方法は
didRegisterForRemoteNotificationsWithDeviceToken
はまだ呼び出されていません。
ドキュメントには :
のregisterForRemoteNotificationsメソッドを呼び出した後、そのメソッドを実行します。 UIApplicationオブジェクトは、デバイスが起動するとこのメソッドを呼び出します。 登録が正常に完了する
didRegisterUser
はよく表示されるが、そうでない
did register notif
.
以下は、AppDelegateのコードです(アプリのバージョンは8.1です)。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//register notif
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
[application registerUserNotificationSettings:settings];
return YES;
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
//register to receive notifications
[application registerForRemoteNotifications];
NSLog(@"didRegisterUser");
}
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"error here : %@", error);//not called
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
/*
// Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
currentInstallation.channels = @[ @"global" ];
[currentInstallation saveInBackground];
*/
NSLog(@"did register notif");//not called
}
また、info.plistにbackground mode ->リモート通知も入れています。
解決方法は?
あなたのコードは正しいようです。ちょっとした改善点として、didRegisterUserNotificationSettingsメソッドを以下のように記述することができます。
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
if (notificationSettings.types != UIUserNotificationTypeNone) {
NSLog(@"didRegisterUser");
[application registerForRemoteNotifications];
}
}
設定に問題があり、APN登録に失敗している可能性があります。
-
Provisioning Profile に aps-environment の項目が含まれていることを確認します。
-
Provisioning Profile に一意の App Identifier("*"を含まない文字列)が設定されていることを確認します。また、Info.plistで、この正確な識別子をバンドル識別子として使用する必要があります。
-
最初のインストール後にPush機能を拒否した可能性があります。この場合、アプリ内Pushアラートは二度と表示されず、設定アプリでPushを再度有効にする必要があります。
-
別の端末で試してみてください。
関連
-
[解決済み】リンカーコマンドが終了コード1で失敗(起動を確認するには-vを使用)、Xcode 8、Swift 3
-
[解決済み】arm64アーキテクチャの未定義シンボルについて
-
[解決済み] Xcode 10でコマンドCompileSwiftが0以外の終了コードで失敗する [重複] 。
-
[解決済み] Xcode コマンド /usr/bin/codesign は終了コード 1 で失敗しました : errSecInternalComponent
-
[解決済み] ペン先を読み込んだが、「表示」コンセントが設定されていない
-
[解決済み] シミュレータへのサービス接続の開始に失敗しました Xcode
-
[解決済み] Objective-C ブロックパラメータ 発行 このブロック宣言はプロトタイプではありません
-
[解決済み] Stringをformatで作成するには?
-
[解決済み] BluetoothのロゴはiPhoneのキャラクターとして利用できますか?
-
[解決済み] あなたのリクエストはエラーを発生させました。[newNullResponse]?
最新
-
nginxです。[emerg] 0.0.0.0:80 への bind() に失敗しました (98: アドレスは既に使用中です)
-
htmlページでギリシャ文字を使うには
-
ピュアhtml+cssでの要素読み込み効果
-
純粋なhtml + cssで五輪を実現するサンプルコード
-
ナビゲーションバー・ドロップダウンメニューのHTML+CSSサンプルコード
-
タイピング効果を実現するピュアhtml+css
-
htmlの選択ボックスのプレースホルダー作成に関する質問
-
html css3 伸縮しない 画像表示効果
-
トップナビゲーションバーメニュー作成用HTML+CSS
-
html+css 実装 サイバーパンク風ボタン
おすすめ
-
[解決済み】Xcode 10.2.1 Command PhaseScriptExecutionが0以外の終了コードで失敗した。
-
[解決済み] Xcode コマンド /usr/bin/codesign は終了コード 1 で失敗しました : errSecInternalComponent
-
[解決済み] 警告: 'characters' は非推奨です。String または Substring を直接使用してください。
-
[解決済み] EXC_CORPSE_NOTIFY シンボルのクラッシュが発生しました、追跡するには?
-
[解決済み] iPhoneが使用できません。デバイスを再接続してください
-
[解決済み] 新しい Swift クラスの void 関数で予期しない非 void の戻り値が発生する。
-
[解決済み] Xcodeのロギング。"Metal API Validation Enabled"
-
[解決済み] 指定されたホスト名を持つサーバーが見つからなかった
-
[解決済み] ブリッジングヘッダ用のプリコンパイルヘッダの発行に失敗しました。
-
[解決済み] Xcodeで実行ファイルが無効なエンタイトルメントで署名されてしまう