我有以下方法来获取推送通知的 UID。可悲的是,它没有被调用。我做错了什么?推送通知的注册正在运行。错误函数未被调用。我在这里快要疯了。
extension AppDelegate {
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
// 1. Convert device token to string
let tokenParts = deviceToken.map { data -> String in
return String(format: "%02.2hhx", data)
}
let token = tokenParts.joined()
// 2. Print device token to use for PNs payloads
print("Device Token: \(token)")
}
func application(
_ application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Error registering notifications: (error)")
}
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UIDevice.current.beginGeneratingDeviceOrientationNotifications()
AppearanceConfigurator.configureNavigationBar()
UIFont.overrideInitialize() …Run Code Online (Sandbox Code Playgroud) 我想在单击事件后调用 RecyclerView.Adapter 中的支持片段管理器,以便移动到不同的片段。我的做法:
(context as MainActivity).supportFragmentManager
.beginTransaction()
.replace(MainActivity.FRAGMENT_CONTAINER, TextScreen())
.commit()
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
kotlin.TypeCastException:null 无法转换为非 null 类型
你能帮助我吗?