【发布时间】:2015-09-01 12:53:48
【问题描述】:
我刚刚按照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()
}
}
另一个问题是我收到了声音和横幅,但没有收到“徽章”
任何帮助将不胜感激......
【问题讨论】:
-
每台设备都会有所不同,这是意料之中的。
-
哦!然后,如果我有一台服务器,但我不知道有多少人从应用商店下载了我的应用......在这种情况下,我将如何向所有人发送通知??
-
你必须在你的设计(服务器)中加入这个东西,你会将用户的设备 ID 发送到服务器并根据需要发送推送
-
你知道如何与服务器通信吗?根据本教程??如果是,你能解释一下吗?
标签: swift ios8 push-notification apple-push-notifications