我使用 Backendless 作为后端(BaaS)。我刚刚注意到,Backendless 的服务器目前似乎有问题。我无法在他们的控制台上创建新的应用 ID。我偶然注意到,我所有的应用程序现在在应用程序启动期间都崩溃了。
我所有的应用程序都有相同的代码AppDelegate.swift
:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
backendless.initApp(APP_ID, secret: SECRET_KEY, version: VERSION_NUM)
backendless.messaging.registerForRemoteNotifications()
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
application.applicationIconBadgeNumber = 0
application.cancelAllLocalNotifications()
return true
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
print("token: \(deviceToken)")
// prepare the token to be saved from <xxxxxxxx xxxxxxxx...> to xxxxxxxxxxxxxxxxx...
var token = NSString(format: "%@", deviceToken)
token = token.stringByReplacingOccurrencesOfString(
"<",
withString: "")
token = token.stringByReplacingOccurrencesOfString(
">",
withString: "")
token = token.stringByReplacingOccurrencesOfString(" ", withString: "")
print(token)
if Reachability.isConnectedToNetwork() == true {
backendless.messaging.registerDeviceToken(token as String)
}
}
我已经检查了可达性是否为真,但我的所有应用程序现在仍然崩溃,因为可达性为真,但后端已关闭...如果 3rd 方服务关闭,我如何避免应用程序崩溃?
非常感谢帮助。
我的Reachability.swift
:
import Foundation
import SystemConfiguration
public class Reachability {
class func isConnectedToNetwork() -> Bool {
var zeroAddress = sockaddr_in()
zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))
zeroAddress.sin_family = sa_family_t(AF_INET)
guard let defaultRouteReachability = withUnsafePointer(&zeroAddress, {
SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0))
}) else {
return false
}
var flags : SCNetworkReachabilityFlags = []
if !SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags) {
return false
}
let isReachable = flags.contains(.Reachable)
let needsConnection = flags.contains(.ConnectionRequired)
return (isReachable && !needsConnection)
}
}
应用程序崩溃日志的一部分:
Incident Identifier: XX
CrashReporter Key: XX
Hardware Model: iPhone8,1
Process: DJ Remake [4153]
Path: /private/var/containers/Bundle/Application/567B8C2E-C288-454B-B11C-C35F93FB56DD/DJ Remake.app/DJ Remake
Identifier: com.davidseek.dj-remake
Version: 1 (1.0.2)
Code Type: ARM-64 (Native)
Parent Process: launchd [1]
Date/Time: 2016-04-29 12:07:54.54 +0200
Launch Time: 2016-04-29 12:06:53.53 +0200
OS Version: iOS 9.3.1 (13E238)
Report Version: 105
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Filtered syslog:
None found
Global Trace Buffer (reverse chronological seconds):
0.116172 CFNetwork 0x0000000181819f30 NSURLConnection finished with error - code -1001
60.589908 CFNetwork 0x0000000181729a44 TCP Conn 0x154699a70 SSL Handshake DONE
60.884066 CFNetwork 0x0000000181729954 TCP Conn 0x154699a70 starting SSL negotiation
60.884409 CFNetwork 0x00000001817cbda4 TCP Conn 0x154699a70 complete. fd: 9, err: 0
60.885311 CFNetwork 0x00000001817cd2d0 TCP Conn 0x154699a70 event 1. err: 0
61.043184 CFNetwork 0x00000001817cbda4 TCP Conn 0x1545a8190 complete. fd: 5, err: 0
61.043698 CFNetwork 0x00000001817cd2d0 TCP Conn 0x1545a8190 event 1. err: 0