但是当我使用休斯顿模拟向我的设备发送通知时,我可以从控制台获得1推送通知成功消息,但设备端没有动作或日志.似乎dIDReceiveIncomingPushWithPayload永远不会被调用.
附:我正在使用Xcode 7.3,iPhone 6(iOS 9.3)和iPad Mini(iOS 9.3)进行开发.分布式Ad Hoc ipa用于安装.
这里的代码发布了.
import UIKitimport PushKit@UIApplicationMainclass AppDelegate: UIResponder,UIApplicationDelegate {var window: UIWindow?let voipRegistry = PKPushRegistry(queue: dispatch_get_main_queue())func application(application: UIApplication,dIDFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // OverrIDe point for customization after application launch. //Enable all notification type. VoIP Notifications don't present a UI but we will use this to show local nofications later let notificationSettings = UIUserNotificationSettings(forTypes: [UIUserNotificationType.Alert,UIUserNotificationType.Badge,UIUserNotificationType.sound],categorIEs: nil) //register the notification settings application.registerUserNotificationSettings(notificationSettings) //output what state the app is in. This will be used to see when the app is started in the background NSLog("app launched with state \(application.applicationState.stringValue)") return true} func applicationWillTerminate(application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDIDEnterBackground:. //output to see when we terminate the app NSLog("app terminated")}}extension AppDelegate {func application(application: UIApplication,dIDRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) { //register for voip notifications NSLog("dIDRegisterUserNotificationSettings called") voipRegistry.desiredPushTypes = Set([PKPushTypeVoIP]) voipRegistry.delegate = self;}}extension AppDelegate: PKPushRegistryDelegate {func pushRegistry(registry: PKPushRegistry!,dIDUpdatePushCredentials credentials: PKPushCredentials!,forType type: String!) { NSLog("dIDUpdatePushCredentials called") //print out the VoIP token. We will use this to test the nofications. NSLog("voip token: \(credentials.token)")}func pushRegistry(registry: PKPushRegistry!,dIDReceiveIncomingPushWithPayload payload: PKPushPayload!,forType type: String!) { NSLog("dIDReceiveIncomingPushWithPayload called") let payloadDict = payload.dictionaryPayload["aps"] as? Dictionary<String,String> let message = payloadDict?["alert"] //present a local notifcation to visually see when we are recIEving a VoIP Notification if UIApplication.sharedApplication().applicationState == UIApplicationState.Background { NSLog("incoming notificaiton from background") let localnotification = UIlocalnotification(); localnotification.alertbody = message localnotification.applicationIconBadgeNumber = 1; localnotification.soundname = UIlocalnotificationDefaultSoundname; UIApplication.sharedApplication().presentlocalnotificationNow(localnotification); } else { NSLog("incoming notificaiton from frontend") dispatch_async(dispatch_get_main_queue(),{ () -> VoID in let alertController = UIAlertController(Title: "Title",message: "This is UIAlertController default",preferredStyle: UIAlertControllerStyle.Alert) let cancelAction = UIAlertAction(Title: "Cancel",style: UIAlertActionStyle.Cancel,handler: nil) let okAction = UIAlertAction(Title: "OK",style: UIAlertActionStyle.Default,handler: nil) alertController.addAction(cancelAction) alertController.addAction(okAction) UIApplication.sharedApplication().keyWindow?.rootVIEwController?.presentVIEwController(alertController,animated: true,completion: nil) }) } NSLog("incoming voip notfication: \(payload.dictionaryPayload)")}func pushRegistry(registry: PKPushRegistry!,dIDInvalIDatePushTokenForType type: String!) { NSLog("dIDInvalIDatePushTokenForType called") NSLog("token invalIDated")}} extension UIApplicationState {//help to output a string instead of an enum numbervar stringValue : String { get { switch(self) { case .Active: return "Active" case .Inactive: return "Inactive" case .Background: return "Background" } }}}
有关如何收到此类通知的任何想法?
解决方法 最后我解决了这个问题.有OK的迅速源代码,这个问题是我错发送推送请求苹果的开发服务器gateway.sandBox.push.apple.com,其实我们应该请求发送到苹果的生产服务器gateway.push.apple.com.
如果你正在跟踪M Penades’ procedure,请注意,您需要修改脚本Simplepush,只需更换SSL:SSL由2195://gateway.push.apple.com://gateway.sandBox.push.apple.com 2195在第20行和再试一次.
希望对你有效.
总结以上是内存溢出为你收集整理的ios – 无法使用PushKit接收VoIP通知全部内容,希望文章能够帮你解决ios – 无法使用PushKit接收VoIP通知所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)