GCMを長時間使用しています。ある日突然それが壊れた。問題は、私が最初のプッシュを送ると私は成功ステータスに戻りますが、アプリは何のプッシュも受け取りません。 2回目のプッシュはNotRegisteredエラーで失敗します。私はアプリを再インストールします:成功(通知なし)、失敗(NotRegistered) - >ループ。私は何が変わったのか分からない。 Googleのサポートは非常に役に立たず、GCMの問題、APNの問題、クライアントの問題など、簡単な質問に多くの時間を費やしています。以前に誰かがこのような問題を抱えていたら、何を探したらいいのか教えてください。私はそれは私もよく分からないのiOS 9にアップデートした後に起こったことを疑うGCM IOS NotRegistered issue
:それは次のように、それがどのように見えるかです。新しいiOSにGCMをブロックしているものがある場合は、誰かがそれを指摘していただければ幸いです。
UPDATE:男は同様の問題があった
GCM push fails with NotRegistered
。問題はいくつかのマニフェストファイルで発生しました。 Info.plistに、GCMを許可するためにiOS 9用に追加する必要があるエントリがいくつかありますか?
UPDATE:onTokenRefreshたびアプリが起動
と呼ばれています。私は同じトークンを取り戻しています。そこで、GCMサーバー上のトークンに問題があると思われます。
APPDELEGATE、IN GCM DELEGATE CODE:
var connectedToGCM = false
private var deviceToken: NSData?
var gcmSenderID: String!
let authorizedEntity = "my GCM Sender_ID"
public func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
var configureError:NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")
gcmSenderID = GGLContext.sharedInstance().configuration.gcmSenderID
// [END_EXCLUDE]
// Register for remote notifications
if #available(iOS 8.0, *) {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
} else {
// Fallback
let types: UIRemoteNotificationType = [.Alert, .Badge, .Sound]
application.registerForRemoteNotificationTypes(types)
}
// [END register_for_remote_notifications]
// [START start_gcm_service]
let gcmConfig = GCMConfig.defaultConfig()
GCMService.sharedInstance().startWithConfig(gcmConfig)
return true
}
public func onTokenRefresh() {
print("Token needs to be refreshed!")
let options = [
kGGLInstanceIDRegisterAPNSOption : deviceToken!,
kGGLInstanceIDAPNSServerTypeSandboxOption : true
]
GGLInstanceID.sharedInstance().tokenWithAuthorizedEntity(authorizedEntity, scope: kGGLInstanceIDScopeGCM, options: options) { (token, error) -> Void in
if error != nil {
print("Error: \(error.localizedDescription)")
} else {
print("Token: \(token)")
}
}
}
public func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
public func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let instanceIDConfig = GGLInstanceIDConfig.defaultConfig()
instanceIDConfig.delegate = self
// Start the GGLInstanceID shared instance with that config and request a registration
// token to enable reception of notifications
GGLInstanceID.sharedInstance().startWithConfig(instanceIDConfig)
self.deviceToken = deviceToken
}
public func applicationDidEnterBackground(application: UIApplication) {
GCMService.sharedInstance().disconnect()
connectedToGCM = false
}
public func applicationDidBecomeActive(application: UIApplication) {
print("App became active")
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
// Connect to the GCM server to receive non-APNS notifications
GCMService.sharedInstance().connectWithHandler({
(NSError error) -> Void in
if error != nil {
print("Could not connect to GCM: \(error.localizedDescription)")
} else {
self.connectedToGCM = true
print("Connected to GCM")
// ...
}
})
}
public func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
print("Notification received: \(userInfo)")
GCMService.sharedInstance().appDidReceiveMessage(userInfo)
}
public func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
print("Error registering")
}
public func application(application: UIApplication,
didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler handler: (UIBackgroundFetchResult) -> Void) {
print("Notification received(background): \(userInfo)")
NotificationManager.sharedInsteance().parseNotification(userInfo)
// This works only if the app started the GCM service
GCMService.sharedInstance().appDidReceiveMessage(userInfo);
// Handle the received message
// Invoke the completion handler passing the appropriate UIBackgroundFetchResult value
// [START_EXCLUDE]
handler(UIBackgroundFetchResult.NewData);
// [END_EXCLUDE]
}
UPDATE
OK、私は、私は(それが何らかの理由でルートではありませんでした)の.plist位置が台無しに信じます。私はルートに移動し、GCMを開始するときにこの警告/エラーが表示されます:
UPD さて、実際には1回だけ起こって停止しました。だから私は問題がここにあるとは思わない。
.plistをルートディレクトリtoTokenRefresh()で移動した後、呼び出しが停止しましたが、まだ私はNotRegisteredを取得しています。
GCMのアプリケーション代理人に実装したコールバックを含めることができますか? –
これは、通常、無効なAPNトークンで発生します。 GCMに登録するために使用しているAPNSトークンが特定のサーバーに対して有効であることを確認してください。たとえば、Sandbox APNSトークンを使用して、PROD証明書で署名されたアプリにメッセージを送信していないとします。また、GCMに登録するときに、 'kGGLInstanceIDAPNSServerTypeSandboxOption'に値を正しく割り当てていることを確認してください。 – evanescent
私は正しいサンドボックスオプションを使用しています。トークンが無効であるかどうかを確認するにはどうすればよいですか? –