我在 Swift 中执行 Google Cloud Messaging 时遇到问题。将 GCMExample
用于 objective-c ,我得到了注册 token ,但是当我尝试运行用于 Swift 的 GCMExampleSwift
时,我收到了一个错误。我为 Objective C 和 Swift 使用相同的“GoogleService-Info.plist”。
2015-10-26 17:31:59.834 GcmExampleSwift[360:51727] The configuration file 'GoogleService-Info.plist' is for another bundle identifier ('com.XXXXXX.mobility.appfactory.dev1.social'). Using this file the services may not be configured correctly. To continue with this configuration file, you may change your app's bundle identifier to 'com.XXXXXX.mobility.appfactory.dev1.social'. Or you can download a new configuration file that matches your bundle identifier from https:/ 2015-10-26 17:31:59.836 GcmExampleSwift[360:] App measurement v.1100000 started 2015-10-26 17:31:59.843 GcmExampleSwift[360:51727] Successfully configured [CloudMessaging]. 2015-10-26 17:31:59.843 GcmExampleSwift[360:51727] Failed to configure []. 2015-10-26 17:31:59.843 GcmExampleSwift[360:51727] Subspecs not present, so not configured [Analytics, AdMob, SignIn, AppInvite, Maps]. 2015-10-26 17:31:59.843 GcmExampleSwift[360:51727] Subspecs expected to be present [CloudMessaging, Measurement]. 2015-10-26 17:31:59.936 GcmExampleSwift[360:] Network status has changed. code, status: 2, Connected 2015-10-26 17:31:59.977: GGLInstanceID | Unable to find token in cache Error Domain=com.google.iid Code=-25300 "(null)" Registration to GCM failed with error: The operation couldn’t be completed. (com.google.HTTPStatus error 401.) 2015-10-26 17:32:01.053 GcmExampleSwift[360:51727] - changing property masksToBounds in transform-only layer, will have no effect 2015-10-26 17:32:01.053 GcmExampleSwift[360:51727] - changing property masksToBounds in transform-only layer, will have no effect 2015-10-26 17:32:01.053 GcmExampleSwift[360:51727] - changing property masksToBounds in transform-only layer, will have no effect
最佳答案
您的 GoogleService-Info.plist
中的 Bundle ID 似乎与您的目标中的 bundle ID 不匹配。
首先,您需要将 GoogleService-Info.plist
文件添加到正确的目标,如果您尝试使用 GcmExampleSwift
,则应选择它作为目标:
然后在您的 GoogleService-Info.plist
文件中,如果您想使用 com.XXXXXX.mobility.appfactory.dev1.social
作为您的包 ID,请确保您为 BUNDLE_ID
键拼写正确:
最后,在您的目标中,确保首先选择 GcmExampleSwift
(不是作为 Objective - C 目标的 GcmExample
),然后制作 Bundle Identifier
与 GoogleService-Info.plist
文件中的 BUNDLE_ID
匹配:
关于ios - Swift Bundle ID 错误中的 GCM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33361326/