gpt4 book ai didi

原生 Swift Push APN

转载 作者:行者123 更新时间:2023-11-30 10:17:41 25 4
gpt4 key购买 nike

使用以下代码创建了配置文件,但是当我尝试运行开发测试时,我得到 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 的见解显示推送弹出窗口。但我在连接推送网络时遇到错误。第一次测试时我收到

 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

最佳答案

我认为您的问题与 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)
}

关于原生 Swift Push APN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29347320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com