Gcm iOS,订阅主题,错误代码3004。

8

我想在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!

2个回答

6

我以前也遇到过这个问题,因为在使用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) 
}

那就是我错过的。非常感谢! - Siamaster
我也遇到了这个问题,但这并没有解决我的错误代码3004。 - oronbz
注意:如果您没有关注GCMServiceGGLInstanceID,请注意它们是不同的! - wangii

1
对我来说问题在于,直到调用GCMService.sharedInstance().startWithConfig(config)之后才能调用GCMPubSub.sharedInstance(),因此在实际调用subscribeWithToken之前不能将GCMPubSub.shareInstance()存储为属性。请注意保留HTML标签。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接