import
UIKit
@UIApplicationMain
class
AppDelegate
:
UIResponder
,
UIApplicationDelegate
{
var
window:
UIWindow
?
func
application(_ application:
UIApplication
,
didFinishLaunchingWithOptions
launchOptions: [
UIApplicationLaunchOptionsKey
:
Any
]?) ->
Bool
{
let
userSettings =
UIUserNotificationSettings
(types: [.alert, .badge, .sound],
categories:
nil
)
if
((
UIDevice
.current.systemVersion
as
NSString
).floatValue >= 8.0) {
JPUSHService
.register(forRemoteNotificationTypes: userSettings.types.rawValue,
categories:
nil
)
}
else
{
JPUSHService
.register(forRemoteNotificationTypes: userSettings.types.rawValue,
categories:
nil
)
}
JPUSHService
.setup(withOption:
nil
, appKey:
"7b96331738ea713195698fd"
,
channel:
"Publish Channel"
, apsForProduction:
false
)
return
true
}
func
application(_ application:
UIApplication
,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken:
Data
) {
JPUSHService
.registerDeviceToken(deviceToken)
}
func
application(_ application:
UIApplication
,
didReceiveRemoteNotification userInfo: [
AnyHashable
:
Any
],
fetchCompletionHandler
completionHandler:
@escaping
(
UIBackgroundFetchResult
) ->
Void
) {
JPUSHService
.handleRemoteNotification(userInfo)
completionHandler(
UIBackgroundFetchResult
.newData)
}
func
application(_ application:
UIApplication
,
didFailToRegisterForRemoteNotificationsWithError error:
Error
) {
NSLog
(
"did Fail To Register For Remote Notifications With Error: \(error)"
)
}
}
请发表评论