无法进行推送通知与Sinch合作

时间:2016-04-07 22:57:20

标签: ios swift apple-push-notifications sinch

我试图在我的应用程序上接收用于sinch呼叫的voip(和常规)推送通知工作。

应用程序处于前台时已接收调用的代码。 和当地的nofitications背景

推送证书正在使用推送应用程序在mac发送推送,我按照教程,不知道我错过了什么

我的代码:

class AppDelegate: UIResponder, UIApplicationDelegate, SINCallClientDelegate, SINCallDelegate, SINMessageClientDelegate, SINClientDelegate, SINManagedPushDelegate {

var msgClient:SINMessageClient!
var window: UIWindow?
var applicationKey:String!
var applicationSecret:String!
var environmentHost:String!

var voipClient:SINClient!
var push:SINManagedPush!

func requestUserNotificationPermission() {
    if UIApplication.sharedApplication().respondsToSelector("registerUserNotificationSettings:") {
        let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
        UIApplication.sharedApplication().registerUserNotificationSettings(settings)
        UIApplication.sharedApplication().registerForRemoteNotifications()
    }
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    self.push.application(application, didReceiveRemoteNotification: userInfo)
}


func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
    self.handleLocalNotification(notification)
}

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    self.push.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}

func startSinch() {
    if self.voipClient == nil {
        self.push.registerUserNotificationSettings()
        let userID = "partner-4" //fixed for tests
        self.voipClient = Sinch.clientWithApplicationKey(applicationKey, applicationSecret:applicationSecret,environmentHost:environmentHost,userId: userID)

        self.voipClient.delegate = self;
        //commented to test push but is working
        //self.voipClient.setSupportActiveConnectionInBackground(true)
        self.voipClient.enableManagedPushNotifications()
        self.voipClient.setSupportCalling(true)
        self.voipClient.setSupportMessaging(true);
        self.voipClient.start()
        self.voipClient.startListeningOnActiveConnection()

        self.msgClient = self.voipClient.messageClient()
        self.msgClient.delegate = self

    }

}

func managedPush(managedPush: SINManagedPush!, didReceiveIncomingPushWithPayload payload: [NSObject : AnyObject]!, forType pushType: String!) {
    self.handleRemoteNotification(payload)
}


func handleRemoteNotification(userInfo: NSDictionary){
    if (self.voipClient == nil) {
        self.startSinch()
    }
    self.voipClient.relayRemotePushNotification(userInfo as [NSObject : AnyObject])
}

func client(client: SINCallClient!, localNotificationForIncomingCall call: SINCall!) -> SINLocalNotification! {
    let notification = SINLocalNotification()
    notification.alertAction = "test"
    notification.alertBody = "test"
    notification.soundName = "notification-sound.caf"
    return notification
}

func relayLocalNotification(notification: UILocalNotification) -> SINNotificationResult{
    return self.voipClient.relayLocalNotification(notification)
}

0 个答案:

没有答案
相关问题