我一直在尝试实现VoIP ManagedPush通知,但是它们不起作用。以下是我为实现ManagedPush所采取的步骤:
1)在Apple中创建了一个VoIP服务证书。将证书的.p12文件上载到Sinch。
2)实例化sinchClient和push客户机var sinchClient: SINClient!; var push: SINManagedPush!
3)在didFinishLaunchingWithOptions函数中初始化push客户端和sinch客户端:
// Register for Sinch Notifications (for calling)
self.push = Sinch.managedPushWithAPSEnvironment(.Development)
self.push.delegate = self
self.push.setDesiredPushTypeAutomatically()
// Sinch
NSNotificationCenter.defaultCenter().addObserverForName("UserDidLoginNotification", object: nil, queue: nil, usingBlock: {(note: NSNotification) -> Void in
self.initializeSinch(note.userInfo!["userId"] as! String)
})4)初始化sinchClient。当用户通过facebook登录时被调用。
func initializeSinch(loginId: String){
sinchClient = Sinch.clientWithApplicationKey("key", applicationSecret: "secret", environmentHost: "sandbox.sinch.com", userId: loginId)
sinchClient.callClient().delegate = self
sinchClient.setSupportCalling(true)
sinchClient.enableManagedPushNotifications()
sinchClient.start()
sinchClient.startListeningOnActiveConnection()
self.push.registerUserNotificationSettings()
}5)在函数didRegisterForRemoteNotificationsWithDeviceToken中,我放置了以下代码行:
self.push.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)6)在函数didRecieveRemoteNotification中,我放置了以下代码行:
self.push.application(application, didReceiveRemoteNotification: userInfo)7)为SINManagedPushDelegate创建委托函数
extension AppDelegate: SINManagedPushDelegate{
func managedPush(managedPush: SINManagedPush!, didReceiveIncomingPushWithPayload payload: [NSObject : AnyObject]!, forType pushType: String!) {
self.handleRemoteNotification(payload)
print("HERE GOT A REMOTE NOTIFICATIOn")
}
func handleRemoteNotification(userInfo: [NSObject : AnyObject]) {
if (sinchClient == nil) {
let userManager = UserManager()
initializeSinch(String(userManager.user.facebookId))
}
self.sinchClient.relayRemotePushNotification(userInfo)
}
}因此,我的问题真的归结为我做错了什么,ManagedPush没有工作。我读过SinchCallingPush,并对其进行了转换,并试图完全按照代码执行,但它仍然不起作用。我认为这可能与不实现PushKit有关。如果是这样的话,请有人指出如何正确地导入它以及在哪里使用它。
我也在https://stackoverflow.com/questions/37577566/instant-message-push-notification-using-sinch-not-coming-on-ios看过一个类似的问题
发布于 2016-06-04 21:48:49
出了点事就开始起作用了。现在,我收到了一个错误,上面写着SIN_INCOMING_CALL。我相信我可以搜索并解决这个问题。
https://stackoverflow.com/questions/37635146
复制相似问题