我有一个iOS应用程序,我正在成功地使用仙鸟。然而,当应用程序在后台运行时,接收通知的功能不起作用。实际上,当我试图在AppSelegate.swift文件中注册这些通知的用户时,我得到了错误800101 ERR_CONNECTION_REQUIRED,这表明我没有正确地连接到Sendbird服务器。但是,我已经检查了连接的建立,并且在尝试注册这些通知之前,在应用一启动时就没有出现错误。
这是用于建立连接的代码:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
SBDMain.initWithApplicationId(Constants.SENDBIRD_APP_ID, useCaching: false) {
} completionHandler: { error in
print(error)
}
...
}这是我试图注册的代码:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
SBDMain.registerDevicePushToken(deviceToken, unique: true, completionHandler: { (status, error) in
if error == nil {
if status == SBDPushTokenRegistrationStatus.pending {
return
}
else {
print("Successfully registered")
}
}
else {
print(error)
}
})
}如前所述,我已经确保sendbird应用程序在注册之前已经初始化,但是由于某种原因,在尝试注册推送通知时,我会得到“连接所需”错误。其余的Sendbird功能可以正常工作,所以我想连接已经建立得很好了。这些通知在使用相同数据的Android上运行良好。
发布于 2022-05-06 01:07:22
免责声明:我是仙鸟公司的员工。
嗨皮皮托,
我不确定您使用的是哪个版本,但是在尝试注册令牌之前,您可能不会调用实际的connect方法。
创建连接时有两个步骤。第一个是使用应用程序ID初始化SDK,第二个是使用userId和accessToken调用connect方法(如果您正在使用它们)。
// Initialize a SBDMain instance to use APIs in the client app.
SBDMain.initWithApplicationId(APP_ID, useCaching: false) {
} completionHandler: { error in
}
// The USER_ID below should be unique to your Sendbird application.
SBDMain.connect(withUserId: USER_ID, completionHandler: { (user, error) in
guard error == nil else {
// Handle error.
}
// The user is connected to Sendbird server.
...
})如果你在这之后仍然有问题,我建议你到我们的社区论坛,以便我们可以从你获得更多的信息。https://community.sendbird.com
https://stackoverflow.com/questions/72132799
复制相似问题