同一应用程序

时间:2015-09-01 12:53:48

标签: swift ios8 push-notification apple-push-notifications

我只是按照http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1的教程来创建示例推送通知示例....

但我不知道在哪里出错我在同一应用程序的不同设备上收到不同的令牌ID

这是我的参考代码,

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()
        }
    }

还有一个问题是我收到了声音和横幅,但没有&#34;徽章&#34;

任何帮助都将不胜感激....

1 个答案:

答案 0 :(得分:1)

在你的“didRegisterForRemoteNotificationsWithDeviceToken”中 将您的设备令牌发送到这样的服务器

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >

</RelativeLayout>

请注意,HDDataLayer是我自己的类,您将使用您正在使用的类与您的服务器进行交互。