• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

php - 适用于 iOS 的 Google 云消息传递 MismatchSenderId

[复制链接]
菜鸟教程小白 发表于 2022-12-13 13:37:02 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

目前对 IOS 的 GCM 推送通知存在问题。

我尝试了不同的教程,但仍然无法通过 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("OST", 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"}]}



Best Answer-推荐答案


基于 Downstream error response codes GCM 部分

A registration token is tied to a certain group of senders. When a client app registers for GCM, it must specify which senders are allowed to send messages. You should use one of those sender IDs when sending messages to the client app. If you switch to a different sender, the existing registration tokens won't work.

关于php - 适用于 iOS 的 Google 云消息传递 MismatchSenderId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34792791/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap