Aravind
Aravind

Reputation: 845

Different APN Device Token ID for same application

I just followed the tutorial of http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1 for creating a sample push notification example....

But I dono where I went wrong I am receiving different token ID on different devices for the same application.

Here is my code for reference,

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        var type = UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound;
        var setting = UIUserNotificationSettings(forTypes: type, categories: nil);
        UIApplication.sharedApplication().registerUserNotificationSettings(setting);
        UIApplication.sharedApplication().registerForRemoteNotifications();

        return true
    }


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

        println("My token is \(deviceToken)")  // am getting it different for different devices
    }

    //Called if unable to register for APNS.
    func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {

        println(error)

    }

    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {

        println("Recived: \(userInfo)")
        //Parsing userinfo:
        var temp : NSDictionary = userInfo
        if let info = userInfo["aps"] as? Dictionary<String, AnyObject>
        {
            var alertMsg = info["alert"] as! String
            var alert: UIAlertView!
            alert = UIAlertView(title: "", message: alertMsg, delegate: nil, cancelButtonTitle: "OK")
            alert.show()
        }
    }

One more problem is that I am receiving a sound and banner but not "badge"

Any help would be appreciated....

Upvotes: 0

Views: 408

Answers (1)

Arslan Asim
Arslan Asim

Reputation: 1302

In your "didRegisterForRemoteNotificationsWithDeviceToken" send your device Token to server like this

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    let deviceTokenStr = HDDataLayer.convertDeviceTokenToStr(deviceToken)
    HDDataLayer.postNotificationServiceResponseByUrlString("pushnotifications/notifications/register", andParams: tempDict, andDictCompletion: { (response: AnyObject!, error: NSError!) -> Void in
        NSLog("Device Register successfully")
    })
}

Please Note that HDDataLayer is my own class and you will use class you are using to interact with your server.

Upvotes: 1

Related Questions