0
令牌ID我只是跟着的http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1教程創建樣品推送通知例子....不同的APN設備相同的應用程序
但我DONO我哪裏錯了,我在不同的接收不同的令牌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()
}
}
還有一個問題是,我收到一個聲音和橫幅,但不會「徽章」
任何幫助,將不勝感激....
你會得到不同的每個設備,這是預期的。 –
哦!然後,如果我有一臺服務器,我不知道有多少人從應用程序商店下載了我的應用程序......在這種情況下,我將如何向所有人發送通知? –
你必須在你的設計(服務器)中包含這個東西,你會發送用戶的設備ID到服務器,並根據需要發送推送 –