Я интегрировал GCM в свое приложение, вот код:
import UIKit
import GoogleMaps
import FBSDKLoginKit
@available(iOS 9.0, *)
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GGLInstanceIDDelegate, GCMReceiverDelegate {
var window: UIWindow?
var connectedToGCM = false
var gcmSenderID: String?
var registrationOptions = [String: AnyObject]()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
var configureError:NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")
gcmSenderID = GGLContext.sharedInstance().configuration.gcmSenderID
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil))
application.registerForRemoteNotifications()
let gcmConfig = GCMConfig.defaultConfig()
gcmConfig.receiverDelegate = self
GCMService.sharedInstance().startWithConfig(gcmConfig)
if(launchOptions?[UIApplicationLaunchOptionsLocationKey] != nil){
LocationService.sharedInstance.startMonitoringLocation()
}
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let instanceIDConfig = GGLInstanceIDConfig.defaultConfig()
instanceIDConfig.delegate = self
GGLInstanceID.sharedInstance().startWithConfig(instanceIDConfig)
let registrationOptions = [kGGLInstanceIDRegisterAPNSOption:deviceToken,
kGGLInstanceIDAPNSServerTypeSandboxOption:true]
GGLInstanceID.sharedInstance().tokenWithAuthorizedEntity(gcmSenderID,
scope: kGGLInstanceIDScopeGCM, options: registrationOptions, handler: registrationHandler)
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
print(userInfo)
completionHandler(UIBackgroundFetchResult.NewData)
}
func applicationDidEnterBackground(application: UIApplication) {
GCMService.sharedInstance().disconnect()
connectedToGCM = false
LocationService.sharedInstance.restartMonitoringLocation()
}
func applicationDidBecomeActive(application: UIApplication) {
GCMService.sharedInstance().connectWithHandler({(error:NSError?) -> Void in
if let error = error {
print("Could not connect to GCM: \(error.localizedDescription)")
} else {
self.connectedToGCM = true
print("Connected to GCM")
}
})
FBSDKAppEvents.activateApp()
}
func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
LocationService.sharedInstance.startUpdatingLocationTerminate()
}
func onTokenRefresh() {
// A rotation of the registration tokens is happening, so the app needs to request a new token.
print("The GCM registration token needs to be changed.")
GGLInstanceID.sharedInstance().tokenWithAuthorizedEntity(gcmSenderID,
scope: kGGLInstanceIDScopeGCM, options: registrationOptions, handler: registrationHandler)
}
func registrationHandler(registrationToken: String!, error: NSError!) {
if (registrationToken != nil) {
Gideon.notifId = registrationToken
print("GCM token: \(registrationToken)")
} else {
print("Registration to GCM failed with error: \(error.localizedDescription)")
}
}
А вот мой лог:
2016-04-25 22:57:41.805 TestApp[2044:] Начато измерение приложения v.2003000 2016-04-25 22:57:41.805 TestApp[2044:] Чтобы включить ведение журнала отладки, установите следующий аргумент приложения: -GMRDebugEnabled 2016- 04-25 22:57:41.848: GCM | Библиотека GCM версии 1.1.4 25.04.2016 22:57:41.868: GCM | Invalid key in checkin plist: GMSInstanceIDDeviceDataVersion GCM token: k6uFlJWBSEg:APA91bGASVNpk-TwgturFp8BSVccFmPKtVLIg7MS6tcWNp4nvB26o3zdFVLUq6oqE1DtJOFAISiS6dZFu_Tt_p5c4v1WiQg7kZcq0hNIZKeabhx0Mg-2uzkJIkg-pvmpcvOHSBmtXYVg 2016-04-25 22:57:42.331 TestApp[2044:] App measurement enabled 2016-04-25 22:58:44.642 TestApp[2044 :414848] Ошибка CFNetwork SSLHandshake (-9806) 25-04-2016 22:59:13.425 TestApp[2044:414848] Ошибка CFNetwork SSLHandshake (-9806) 25-04-2016 22:59:34.918 Gideon[2044:414848] CFNetwork Ошибка SSLHandshake (-9806) Подключено к GCM 2016-04-25 23:09:54.593 TestApp[2044:414848] CFNetwork Ошибка SSLHandshake (-9806) 25-04-2016 23:10:08.681 TestApp[2044:414848] CFNetwork SSLHandshake сбой (-9806) 25-04-2016 23:10:27.482 TestApp[2044:414848] CFNetwork SSLHandshake failed (-9806) Не удалось подключиться к GCM: операция не может быть завершена. (ошибка com.google.gcm 2001 г.)
Как я могу исправить эти ошибки:
ГКМ | Недопустимый ключ в списке регистрации: GMSInstanceIDDeviceDataVersion.
CFNetwork SSLHandshake не удалось (-9806)
Не удалось подключиться к GCM: операция не может быть завершена. (ошибка com.google.gcm 2001 г.)
Заранее спасибо