【问题标题】:Swift Push APN nativeSwift Push APN 原生
【发布时间】:2015-03-30 13:20:16
【问题描述】:

使用以下代码创建了配置文件,但是当我尝试运行开发测试时,我得到了 llbd 并且应用程序崩溃了。

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


// Override point for customization after application launch.



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

}



func application(application: UIApplication,   
didFailToRegisterForRemoteNotificationsWithError error: NSError) {

println(error)

 }

能够根据 LastMove 的见解显示推送弹出窗口。但我在连接到 Push 网络时出错。在第一次测试我收到

 Trying 17.172.232.45...
  Connected to gateway.sandbox.push-apple.com.akadns.net

但是当我尝试运行 php 时,我得到了

 Failed to connect: 111 Connection refused 

我也在终端测试中看到:

 openssl s_client -connect gateway.sandbox.push.apple.com:2195 
 CONNECTED(00000003)
 depth=1 /C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated 
 by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification   
 Authority - L1C
 verify error:num=20:unable to get local issuer certificate
 verify return:0
  6236:error:140790E5:SSL routines:SSL23_WRITE:ssl handshake   
 failure:/SourceCache/OpenSSL098
 /OpeJamesJaJamJJJJJJJJJJJJJJaJamJamesJamesJameJamJaJJJJaJaJamess-MacBoJamJa

【问题讨论】:

    标签: swift push uiapplicationdelegate


    【解决方案1】:

    我认为您的问题与 iOS 7/8 有关。 您用于推送通知的 api 是新的。 它不兼容 iOS 7。 如果您需要以 iOS 7 为目标,请使用旧方式。 或更好: https://stackoverflow.com/a/28742391/2327367

    // Register for Push Notitications, if running iOS 8
    if application.respondsToSelector("registerUserNotificationSettings:") {
    
      let types:UIUserNotificationType = (.Alert | .Badge | .Sound)
      let settings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: types, categories: nil)
    
      application.registerUserNotificationSettings(settings)
      application.registerForRemoteNotifications()
    
    } else {      
      // Register for Push Notifications before iOS 8
      application.registerForRemoteNotificationTypes(.Alert | .Badge | .Sound)
    }
    

    【讨论】:

    • 我爱你 LastMove。你愿意嫁给我吗?
    • :d 很高兴它可以帮助你。
    • 虽然,我连接失败:111 Connection denied
    • 您在尝试从服务器发送请求时遇到此错误?
    • 是的。 Godaddy,他们说他们不开放 2195 端口。有没有办法解决这个问题?
    猜你喜欢
    • 2019-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-10
    • 2017-10-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多