pushdeer/ios/PushDeer-iOS/PushDeer/AppDelegate.swift
hext 2136883536 支持微信登录, 修复一些bug:
支持微信登录, 支持同时绑定微信和苹果账号;
解决markdown标题文字显示不全的问题;
markdown中的链接支持内嵌浏览器打开;
增加是否使用内置浏览器的设置项;
改名输入框, 失去焦点的时候也保存;
2022-02-27 23:02:58 +08:00

73 lines
2.7 KiB
Swift

//
// AppDelegate.swift
// PushDeer
//
// Created by HeXiaoTian on 2021/12/31.
//
import UIKit
import UserNotifications
import IQKeyboardManagerSwift
@MainActor
class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
//
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: [.badge, .sound, .alert]) { granted, error in
print("注册通知结果: \(granted) - \(String(describing: error))")
}
application.registerForRemoteNotifications()
//
Task {
let notFirstStart = UserDefaults.standard.bool(forKey: "PushDeer_notFirstStart")
if !notFirstStart {
// APP, , . ()
_ = try await HttpRequest.fake()
UserDefaults.standard.set(true, forKey: "PushDeer_notFirstStart")
}
}
// IQ
IQKeyboardManager.shared.enable = false //
IQKeyboardManager.shared.enableAutoToolbar = true //
#if !targetEnvironment(macCatalyst) && !APPCLIP && !SELFHOSTED
// Mac and AppClip and
//
WXApi.registerApp(Env.wxAppid, universalLink: Env.wxUniversalLink)
#endif
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
print("deviceToken: ", deviceTokenString)
AppState.shared.deviceToken = deviceTokenString
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("didFailToRegisterForRemoteNotificationsWithError: ", error)
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification) async -> UNNotificationPresentationOptions {
print("willPresent:", notification.request.content.userInfo)
Task {
// ,
let messageItems = try await HttpRequest.getMessages().messages
try MessageModel.saveAndUpdate(messageItems: messageItems)
}
return [.sound, .list, .banner]
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async {
print("didReceive:", response.notification.request.content.userInfo)
}
}