Google Cloud Messaging สำหรับ iOS MismatchSenderId

ขณะนี้มีปัญหากับการแจ้งเตือนแบบพุช GCM สำหรับ IOS

ฉันได้ลองใช้บทช่วยสอนต่างๆ แล้ว แต่ยังไม่สามารถผ่าน MismatchSenderid ได้

รหัสที่ฉันใช้แสดงด้านล่างเอาต์พุต -

$msg = array
    (
            'to'       => $registatoin_ids,
            'notification'         => array('subtitle'      => 'Alert message!',
            'badge'       => 1,
            'sound'         => 'default',
            "title" =>  "Notification",
            'body'     => $message)
    );

[registration_ids] => Array
    (
        [0] => ldvBkaxZ0y4:APA91bGP7SWNFZg_BQIum0zKLKyQ6cDZmYi7pQvA5P9ZEjTiI8qiSU7hgX3qL5WnqzDEPTqCfQnqlKAXZ0-0pZkmr6omZO3eI1aAis_R1EaZPdMdtxx_28pkplmuPY2vX1oErkbCuZVB
    )

[data] => Array
    (
        [to] => Array
            (
                [0] => ldvBkaxZ0y4:APA91bGP7SWNFZg_BQIum0zKLKyQ6cDZmYi7pQvA5P9ZEjTiI8qiSU7hgX3qL5WnqzDEPTqCfQnqlKAXZ0-0pZkmr6omZO3eI1aAis_R1EaZPdMdtxx_28pkplmuPY2vX1oErkbCuZVB
            )

        [notification] => Array
            (
                [subtitle] => Alert message!
                [badge] => 1
                [sound] => default
                [title] => Notification
                [body] => Buy One Pizza Today and Get One Free
            )
    ))

รหัส iOS -

import UIKit


@UIApplicationMain

class AppDelegate: UIResponder,UIApplicationDelegate,AsyncDataProviderDelegate,GGLInstanceIDDelegate {

    var window: UIWindow?

    var successToken = ""

    var launchOpt : NSDictionary?

    var rootControllerVC : UIViewController?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.whiteColor()], forState:.Normal)

        UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor(red: 10.00/255.00, green: 32.00/255.00, blue: 32.00/255.00, alpha: 1)], forState:.Selected)


        let tabFont = UIFont(name:"Helvetica-Bold", size: 12)

        UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.whiteColor(), NSFontAttributeName: tabFont!], forState:.Normal)


        if #available(iOS 8.0, *)
        {
            let types:UIUserNotificationType = ([.Alert, .Sound, .Badge])

            let settings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: types, categories: nil)

            application.registerUserNotificationSettings(settings)

            application.registerForRemoteNotifications()
        } else
        {
            application.registerForRemoteNotificationTypes([.Alert, .Sound, .Badge])
        }

        UIApplication.sharedApplication().applicationIconBadgeNumber = 0

        NetworkManager.sharedInstance.delegate = self

        // Override point for customization after application launch.

        return true
    }

    func callRegisterAPi(regId : String)
    {
        let detailDict = NSMutableDictionary()

        detailDict.setObject(kDeviceType, forKey:deviceType)

        detailDict.setObject(kDeviceId, forKey:deviceId)

        detailDict.setObject(regId, forKey: registerID)

        detailDict.setObject(kguiVersion, forKey:guiVersion)

        NetworkManager.sharedInstance.registerDeviceApi("POST", isAsynchronous: true, userDictionary: detailDict)
    }


    //MARK:- AsyncData Provider delegate


    func dataGivenBack(resultDataDict: NSMutableDictionary, methodName: String) {
        if successToken != ""
        {
            NSUserDefaults.standardUserDefaults().setObject(successToken, forKey:kToken)
        }
    }


    //MARK:- Push Notification Delegate Methods


    func application(application: UIApplication,didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)

    {
        let characterSet: NSCharacterSet = NSCharacterSet( charactersInString: "<>" )

        let deviceTokenString: String = ( deviceToken.description as NSString ).stringByTrimmingCharactersInSet( characterSet ).stringByReplacingOccurrencesOfString( " ",withString: "" ) as String

        print("token is \(deviceTokenString)")

        // Create a config and set a delegate that implements the GGLInstaceIDDelegate protocol.

        let instanceIDConfig = GGLInstanceIDConfig.defaultConfig()

        instanceIDConfig.delegate = self

        // Start the GGLInstanceID shared instance with that config and request a registration

        // token to enable reception of notifications

        GGLInstanceID.sharedInstance().startWithConfig(instanceIDConfig)

        let registrationOptions = [kGGLInstanceIDRegisterAPNSOption:deviceToken,

            kGGLInstanceIDAPNSServerTypeSandboxOption:true]

        let gcmSenderID = "83985659474"

        GGLInstanceID.sharedInstance().tokenWithAuthorizedEntity(gcmSenderID,

            scope: kGGLInstanceIDScopeGCM, options: registrationOptions, handler: registrationHandler)
    }

    func registrationHandler(registrationToken: String!, error: NSError!) {
        if (registrationToken != nil) {
            successToken = registrationToken

            print("GCM Token is :\(registrationToken)")

            if isDeviceTokenChanged(registrationToken)
            {
                callRegisterAPi(registrationToken)
            }

            print("Registred")
        } else {
            print("Registration to GCM failed with error: \(error.localizedDescription)")
        }
    }

    func onTokenRefresh() {
        let registrationOptions = [kGGLInstanceIDRegisterAPNSOption:successToken,

            kGGLInstanceIDAPNSServerTypeSandboxOption:true]

        let gcmSenderID = "83985659474"

        // A rotation of the registration tokens is happening, so the app needs to request a new token.

        print("The GCM registration token needs to be changed.")

        GGLInstanceID.sharedInstance().tokenWithAuthorizedEntity(gcmSenderID,

            scope: kGGLInstanceIDScopeGCM, options: registrationOptions as [NSObject : AnyObject], handler: registrationHandler)
    }

    // Called if unable to register for APNS.

    func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError)

    {
        print("not registered to APNS,\(error)")
    }

    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void)

    {
        GCMService.sharedInstance().appDidReceiveMessage(userInfo);

        print("Receiving dict is :\(userInfo)")

        rootControllerVC  = mainStoryBoard.instantiateViewControllerWithIdentifier("startingPage") as UIViewController

        self.window?.rootViewController = rootControllerVC

        UIApplication.sharedApplication().applicationIconBadgeNumber = 0


        completionHandler(UIBackgroundFetchResult.NewData)
    }

    func applicationDidBecomeActive(application: UIApplication) {

        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.


        GCMService.sharedInstance().connectWithHandler({

            (NSError error) -> Void in

            if error != nil {
                print("Could not connect to GCM: \(error.localizedDescription)")

            } else
            {
                //                self.connectedToGCM = true

                print("Connected to GCM")

                // ...
            }
        })
    }
}

{"multicast_id":8936417917512172262,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id:0:1452846200241751%bcdb604df9fd7ecd"}]}


person Aslan Kaya    schedule 14.01.2016    source แหล่งที่มา
comment
ตรวจสอบคำตอบที่ stackoverflow.com/q/11313342/517134 ดูเหมือนว่าปัญหาจะเหมือนกันหรือคล้ายกัน   -  person Yusuf K.    schedule 15.01.2016
comment
@YusufKARTAL ขอบคุณสำหรับคำตอบของคุณ แต่ฉันไม่ได้รับข้อผิดพลาด MismatchSenderId ฉันกำลังได้รับความสำเร็จ   -  person Anirban    schedule 15.01.2016
comment
ตรวจสอบลิงก์นี้ @YusufKARTAL - main.xfiddle.com/c029e74f/gcmios.php   -  person Anirban    schedule 15.01.2016
comment
@bumba ดูเหมือนว่าจะใช้งานได้ มีปัญหาอะไร?   -  person Yusuf K.    schedule 15.01.2016
comment
แต่ฉันไม่ได้รับอะไรเลยในอุปกรณ์ iOS   -  person Anirban    schedule 15.01.2016
comment
@YusufKARTAL เพิ่มโค้ด iOS ด้วย   -  person Anirban    schedule 15.01.2016
comment
@bumba ตกลงปัญหาของคุณแตกต่างออกไป โปรดตรวจสอบคำตอบของ stackoverflow.com/q/34704736/517134 ฉันหวังว่ามันจะช่วยได้   -  person Yusuf K.    schedule 15.01.2016
comment
@YusufKARTAL คุณช่วยวันของฉันไว้ ใช่ ฉันแค่ต้องเพิ่ม 'ลำดับความสำคัญ' =› 'สูง'   -  person Anirban    schedule 15.01.2016
comment
@bumba ยินดีต้อนรับครับ   -  person Yusuf K.    schedule 15.01.2016


คำตอบ (1)


อิงตามส่วนรหัสตอบกลับข้อผิดพลาดดาวน์สตรีมของ GCM

โทเค็นการลงทะเบียนเชื่อมโยงกับกลุ่มผู้ส่งบางกลุ่ม เมื่อแอปไคลเอ็นต์ลงทะเบียน GCM แอปจะต้องระบุว่าผู้ส่งรายใดที่ได้รับอนุญาตให้ส่งข้อความ คุณควรใช้หนึ่งในรหัสผู้ส่งเหล่านั้นเมื่อส่งข้อความไปยังแอปไคลเอ็นต์ หากคุณเปลี่ยนไปใช้ผู้ส่งรายอื่น โทเค็นการลงทะเบียนที่มีอยู่จะไม่ทำงาน

person adjuremods    schedule 15.01.2016