gpt4 book ai didi

ios - 异常 'Call must be made on main thread' iOS

转载 作者:行者123 更新时间:2023-12-03 13:49:46 25 4
gpt4 key购买 nike

我正在一个React Native项目上,该项目通过Firebase Cloud Messaging获得推送通知。已经实现了onNotification(),onNotificationOpened()和getInitialNotification()的方法。虽然当应用程序在前台并强制关闭时通知正常工作,但是当应用程序在后台时打开通知时出现错误(不是强制关闭)。错误图像如下。我尝试更改/注释通知代码,但是错误仍然存​​在。我对React Native还是很陌生,不知道为什么会发生此特定问题。这方面的任何帮助都将非常有帮助。我已经更新了所有与Firebase和云消息传递有关的pod。以下也是 native 代码。我尚未在Xcode中完成任何编码,因此Pod文件保持原样。 [在此处输入图片描述] [1]
![1]:/image/Bg7Us.png

async createNotificationListeners() {
this.notificationListener = firebase.notifications().onNotification((notification) => {
if (notification) {
//const {title, body, data} = notification;
//this.displayNotification(title, body, data);
}
});

this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notification) => {
const {data} = notification.notification;
if (data.url !== undefined) {
this.navigate2URL(data.url);
}else {
this.setState({url: 'test'});
this.webRef.reload();

}
//this.displayNotification(title, body + data);
});

const notificationOpen = await firebase.notifications().getInitialNotification();
if (notificationOpen) {
const {data} = notificationOpen.notification;
if (data.url !== undefined) {
this.setState({url: data.url});
} else {
this.setState({url: 'test'});
}
this.webRef.reload();
//this.displayNotification(title, body);
}
}

最佳答案

在./node_modules/react-native-firebase/ios/RNFirebase/notifications/RNFirebaseNotifications.m中尝试此try-catch

RCT_EXPORT_METHOD(complete:(NSString*)handlerKey fetchResult:(UIBackgroundFetchResult)fetchResult) {
if (handlerKey != nil) {
void (^fetchCompletionHandler)(UIBackgroundFetchResult) = fetchCompletionHandlers[handlerKey];
if (fetchCompletionHandler != nil) {
fetchCompletionHandlers[handlerKey] = nil;
@try {
fetchCompletionHandler(fetchResult);
}
@catch (NSException * e) {
NSLog(@"Exception fetchCompletionHandler: %@", e);
};
} else {
void(^completionHandler)(void) = completionHandlers[handlerKey];
if (completionHandler != nil) {
completionHandlers[handlerKey] = nil;
@try {
completionHandler();
}
@catch (NSException * e) {
NSLog(@"Exception completionHandler: %@", e);
};

}
}
}}

关于ios - 异常 'Call must be made on main thread' iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64565093/

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