Ich entwickle eine reag native iOS -Anwendung, die Live -Aktivitäten verwendet. Ich habe die Live-Aktivitätenfunktionen mit nativen Modulen (Objective-C/Swift) implementiert, um mit den zugrunde liegenden iOS-APIs zu interagieren. Updates für die Live -Aktivität werden über APNs -Push -Benachrichtigungen ausgelöst. Manchmal, wenn ich eine Push -Benachrichtigung sende, aktualisiert die Live -Aktivität korrekt und zeigt die neuen Informationen an. In anderen Fällen kommt die Benachrichtigung ein (ich kann sie in den Konsolenprotokollen sehen oder ein Push -Benachrichtigungstest -Tool verwenden), aber die Live -Aktivität bleibt unverändert. Es gibt kein konsistentes Muster, wenn die Updates erfolgreich sind oder fehlschlagen. > APNS-Setup überprüfen: Ich habe mein APNS-Setup doppelt überprüft, einschließlich der Bereitstellungsprofile, Zertifikate und der Push-Benachrichtigung. Die Nutzlast enthält das erforderliche APS Wörterbuch mit dem inhaltlich verfügbaren -Staste auf 1, und ich schließe auch den Warnwarntaste für das Testen ein (obwohl ich verstehe, dass es nicht streng für den Hintergrund erforderlich ist Updates). Ich habe bestätigt, dass das Gerät die Push -Benachrichtigung zuverlässig empfängt. gründlich den nativen Modulcode überprüft, der die Live -Aktivitätsaktualisierungen übernimmt. Ich verwende Activity.Update , um die Attribute der Aktivität zu aktualisieren. Ich habe dem nativen Modul die Protokollierung hinzugefügt, um zu bestätigen, dass die Aktualisierungsfunktion aufgerufen wird, wenn eine Push -Benachrichtigung empfangen wird. Die Protokolle zeigen, dass die Funktion auch dann aufgerufen wird, wenn die Live -Aktivität nicht aktualisiert wird, was darauf hindeutet, dass das Problem mit der Aktivität liegt. update. Insbesondere die Optionen "Hintergrundabfertigungen" und "Remote -Benachrichtigungen". Ich habe sowohl auf physischen Geräten als auch auf Simulatoren getestet, die verschiedene iOS -Versionen ausführen, aber das intermittierende Verhalten bleibt bestehen. < /P>
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
console.log('Notification.js: Your message was handled in background');
if (DynamicIslandModule && Platform.OS === "ios" && Platform.Version >= 16.1) {
console.log("Notification.js true", remoteMessage);
console.log(DynamicIslandModule, 'DynamicIslandModule');
console.log(remoteMessage?.data?.order, 'order id from background notification');
if (["void", "cancel", "bad", "complete"].includes(remoteMessage?.data?.title.toLowerCase())) {
await DynamicIslandModule.endNotificationActivity();
} else {
await DynamicIslandModule.updateNotificationActivityWithOrderStatus(
remoteMessage?.data?.message,
remoteMessage?.data?.order
);
}
}
if (remoteMessage?.data?.notificationId) {
console.log('Your message was handled in background');
let notificationId = remoteMessage?.data?.notificationId;
await store.getLastSavedToken();
await singleton.markNotificationReceived({ _id: notificationId });
console.log(
'Message handled in the background!',
remoteMessage?.data?.notificationId
);
}
});
< /code>
< /li>
//DynamicIslandModule.swift
@objc(updateNotificationActivityWithOrderStatus:withOrderID:withOrderMessage:withTitle:withResolve:withReject:)
func updateNotificationActivity(
orderStatus: NSString,
orderID: NSString,
orderMessage: NSString,
title: NSString,
resolve: @escaping RCTPromiseResolveBlock,
reject: @escaping RCTPromiseRejectBlock
) {
let status = orderStatus as String
let orderIDString = orderID as String
guard let storedIDs = UserDefaults.standard.array(forKey: "liveActivityIDs") as? [String],
storedIDs.contains(orderIDString) else {
print("ERROR: Live Activity ID not found in UserDefaults")
return
}
guard let liveActivity = Activity.activities.first(where: { activity in
if let contentState = activity.contentState as? NotificationAttributes.ContentState {
return contentState.orderID == orderIDString
}
return false
}) else {
print("ERROR: Live Activity not found for ID: \(orderIDString)")
return
}
guard let currentContentState = liveActivity.contentState as? NotificationAttributes.ContentState else {
print("ERROR: Failed to retrieve current content state")
return
}
let updatedContentState = NotificationAttributes.ContentState(
orderStatus: status,
orderID: orderIDString,
pickupLocation: currentContentState.pickupLocation,
dropoffLocation: currentContentState.dropoffLocation,
serviceMethod: currentContentState.serviceMethod,
orderMessage: orderMessage as String,
title: title as String
)
if #available(iOS 16.1, *) {
print("Updating Live Activity...")
Task {
do {
try await liveActivity.update(using: updatedContentState)
resolve("Live Activity updated successfully for order #\(orderIDString)")
print("Live Activity updated successfully for order #\(orderIDString) status:\(status)")
} catch let error {
reject("ERROR", "Failed to update live activity", error)
print("Error updating live activity: \(error.localizedDescription)")
}
}
} else {
reject("ERROR", "iOS version not supported", nil)
}
}
< /code>
< /li>
//AppDelegate.mm
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
if (@available(iOS 16.1, *)) {
NSString *orderID = userInfo[@"data"][@"order"];
NSString *orderMessage = userInfo[@"data"][@"message"];
NSString *orderStatus = userInfo[@"data"][@"status"];
NSString *orderTitle = userInfo[@"data"][@"title"];
NSLog(@"didReceiveRemoteNotification triggered");
NSArray *endTitles = @[@"complete", @"void", @"bad", @"cancel"];
if ([endTitles containsObject:orderStatus.lowercaseString]) {
[LiveActivityHelper endActivityWithIdWithOrderID:orderID];
} else {
[LiveActivityHelper updateActivityWithOrderID:orderID orderStatus:orderStatus orderMessage:orderMessage title:orderTitle];
}
completionHandler(UIBackgroundFetchResultNewData);
} else {
completionHandler(UIBackgroundFetchResultNewData);
}
}
< /code>
< /li>
< /ul>
Frage: < /p>
Was könnte diese intermittierenden Live -Aktivitätsaktualisierungen verursachen? Gibt es spezielle Überlegungen zu Zeitpunkt, Hintergrundausführung oder APNS -Nutzlaststruktur, die mir möglicherweise fehlt? Alle Vorschläge für das Debuggen würden sehr geschätzt.
## Live -Aktivitäts -Update -Problem in React Native * Titel: * Live -Aktivitäten manchmal aktualisieren Sie manchmal ke ⇐ IOS
-
- Similar Topics
- Replies
- Views
- Last post