【问题标题】:Gcm iOS, subscribe to topic, error code 3004Gcm iOS,订阅主题,错误码3004
【发布时间】:2015-10-12 14:30:54
【问题描述】:

我正在尝试在 iOS 上订阅一个 gcm 主题。

GCMPubSub.sharedInstance().subscribeWithToken(registrationId, topic: "/topics/mytopic", options: nil) { error in  
    print(error.localizedDescription) 
}

操作无法完成。 (com.google.gcm 错误 3004。)

我在任何地方都找不到此错误代码的文档。我还阅读了定义错误的源代码,它看起来像这样:

typedef NS_ENUM(NSUInteger, GCMServiceErrorCode) {
  /**
   *  HTTP errors.
   */

  // InvalidRequest -- Some parameters of the request were invalid.
  kGCMServiceErrorCodeInvalidRequest = 0,

  // Auth Error -- GCM couldn't validate request from this client.
  kGCMServiceErrorCodeAuthentication = 1,

  // NoAccess -- InstanceID service cannot be accessed.
  kGCMServiceErrorCodeNoAccess = 2,

  // Timeout -- Request to InstanceID backend timed out.
  kGCMServiceErrorCodeTimeout = 3,

  // Network -- No network available to reach the servers.
  kGCMServiceErrorCodeNetwork = 4,

  // OperationInProgress -- Another similar operation in progress,
  // bailing this one.
  kGCMServiceErrorCodeOperationInProgress = 5,

  // Unknown error.
  kGCMServiceErrorCodeUnknown = 7,

  /**
   *  Upstream Send errors
   */

  // Upstream send not available (e.g. network issues)
  kGCMServiceErrorCodeUpstreamServiceNotAvailable = 1001,

  // Invalid send parameters.
  kGCMServiceErrorCodeInvalidParameters = 1002,

  // Invalid missing to.
  kGCMServiceErrorCodeMissingTo = 1003,

  // GCM could not cache the message for sending.
  kGCMServiceErrorSave = 1004,

  // Message size exceeded (size > 4KB).
  kGCMServiceErrorSizeExceeded = 1005,

  /**
   *  GCM Connect errors.
   */

  // GCM already connected with the client.
  kGCMServiceErrorCodeAlreadyConnected = 2001,

  /**
   *  PubSub errors.
   */

  // Topic already subscribed to.
  kGCMServiceErrorCodePubSubAlreadySubscribed = 3001,

  // Topic already unsubscribed from.
  kGCMServiceErrorCodePubSubAlreadyUnsubscribed = 3002,

  // Invalid topic name, does not match the topic regex "/topics/[a-zA-Z0-9-_.~%]+"
  kGCMServiceErrorCodePubSubInvalidTopic = 3003,
};

错误代码以 3003 结尾!

【问题讨论】:

    标签: ios google-app-engine google-cloud-messaging publish-subscribe


    【解决方案1】:

    我以前见过这个,因为我在使用GCMPubSub 之前没有启动 GCM。所以这应该为你解决它

    var config = GCMConfig.defaultConfig()
    // Note you should only call start once during the lifetime of your app.
    GCMService.sharedInstance().startWithConfig(config)
    GCMPubSub.sharedInstance().subscribeWithToken(registrationId, topic: "/topics/mytopic", options: nil) { error in  
        print(error.localizedDescription) 
    }
    

    【讨论】:

    • 那是我错过的。非常感谢!
    • 我也遇到了这个问题,这并没有解决我的错误代码 3004
    • 谢谢!任何不关注GCMServiceGGLInstanceID的人注意:两者是不同的!
    【解决方案2】:

    对我来说问题是你甚至不能打电话 GCMPubSub.sharedInstance() 直到您致电 GCMService.sharedInstance().startWithConfig(config) 所以你不能在实际调用subscribeWithToken之前将GCMPubSub.shareInstance()存储为属性

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-24
      • 2018-11-18
      • 1970-01-01
      • 2015-11-23
      • 2020-09-20
      • 1970-01-01
      相关资源
      最近更新 更多