Stream chat: websocket disconnected, chat list not updating on reconnect - ios

Experimenting with Stream's chat service, and we're considering to migrate to it for our iOS app. I'm using version 2.6.2 of their SDK for iOS. I'm getting this error sometimes when the websocket disconnects though:
The image is in Norwegian, but in English it says: The action couldn't be completed (STREAMCHATCLIENT.WEBSOCKETPROVIDERERROR-bug 1).
The list of chats in the ChannelsViewController is purged as part of cleaning the state after a disconnect as is evident in the logs:
[14 Jan 09:36:55.487] [DEBUG] Clearing state after disconnect...
[14 Jan 09:36:55.487] [DEBUG] Cancelling background work...
[14 Jan 09:36:55.489] [DEBUG] :purple_heart: Background mode off
[14 Jan 09:36:55.489] [DEBUG] Disconnecting: Processing finished in background
[14 Jan 09:36:55.491] [DEBUG] Parsing WebSocket disconnect... (error: Cancelled)
[14 Jan 09:36:55.492] [DEBUG] Clearing state after disconnect...
[14 Jan 09:36:55.492] [DEBUG] Cancelling background work...
[14 Jan 09:36:55.492] [ERROR] :x: :broken_heart::rage: Disconnected by error WebSocketProviderError(reason: "Cancelled", code: -1, providerType: StreamChatClient.StarscreamWebSocketProvider, providerError: nil) in websocketDidDisconnect(error:)[304]
The problem is that even though the websocket reconnects shortly, the chat list in the UI is never updated.
How do I prevent errors like these just popping up randomly in the UI, and how do I make sure that the list of chats in the UI is updated after the websocket has reconnected?

It seems that setting the user with Client.shared.set(user:token) multiple times might cause problems. Make sure you don't set a user that has been set already. The error still happens a few times, but not as mugh anymore. I added this check:
guard Client.shared.user.role == .anonymous else {
log("User is already logged in. Aborting chat login process")
return
}
Make note that this check will fail if someone logs in after logging out and the user hasn't been reset properly on logout. In the documentation it says that to log out you have to run Client.shared.disconnect(), but you also have to reset the user with Client.shared.setAnonymousUser(). The ID and everything of the previous user will be removed too.

Related

Firebase Cloud Messaging (FCM) - Data messages are CANCELED by iOS device after restart until app is opened for the first time after device restart

I am using pure data messages from FCM to display notifications locally on my app devices. For some reason, on iOS devices only, the data messages are CANCELED by iOS whenever the device is restarted up until my app is opened for the first time. This leads to my app not receiving any data messages and thus not being able to display notifications and process them accordingly. I am using React Native / Expo to build my app.
This below log lines show iOS cancellations, which continue to retry until the app is opened for the first time following the restart.
iOS Logs:
default 16:57:19.114198+0100 dasd Submitted Activity: com.apple.pushLaunch.XXXXXXXXXXXXXX at priority 5 (Fri Dec 30 16:57:19 2022 - Sat Dec 31 16:57:19 2022)
default 16:57:19.118067+0100 dasd Daemon Canceling Activities: {(
com.apple.pushLaunch.XXXXXXXXXXXXXX
)}
default 16:57:19.118227+0100 dasd CANCELED: com.apple.pushLaunch.XXXXXXXXXXXXXX at priority 5 <private>!
default 17:16:58.004240+0100 dasd com.apple.pushLaunch.XXXXXXXXXXXXXX:[
{name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Absolutely Must Not Proceed, Score: 0.00, Rationale: [{[pushDisallowed]: Required:0.00, Observed:1.00},]}}
], FinalDecision: Absolutely Must Not Proceed}
Once the app is started for the first time, the data messages are received by my app. Following this, the issue does not take place once the app has been started the first time, even if it is is subsequently killed. However, on the next restart, the same issue will take place once again.
The following data message is sent using firebase admin sdk:
Message firebaseMessage = Message.builder()
.putData("notificationId", notificationId)
.putData("title", title)
.putData("body", message)
.putData("imageUrl", imageUrl)
.putData("channelImageUrl", channelImageUrl)
.putData("channelId", "channel-notifications")
.setApnsConfig(ApnsConfig.builder()
.setAps(Aps.builder()
.setContentAvailable(true).build())
.putHeader("apns-push-type", "background")
.putHeader("apns-priority", "5")
.putHeader("apns-topic", <my-app-bundle-id>)
.build())
.setAndroidConfig(AndroidConfig.builder()
.setPriority(AndroidConfig.Priority.HIGH)
.build())
.setToken(recipient)
.build();
The issue does not occur on Android.
Does anyone know what could be wrong and how to fix for my app to start receiving data messages even after a restart on iOS?

SwiftUI app does not run Tasks after haptics engine error

Sometimes, after the app is resumed from background it shows these messages in the log:
2022-03-23 19:16:53.423801+0000 AppName[15711:6706975] [hapi] CHHapticEngine.mm:595 -[CHHapticEngine createHapticPlayerWithOptions:]: ERROR: Server failure: Error Domain=com.apple.CoreHaptics Code=-4810 "(null)"
2022-03-23 19:16:53.424531+0000 AppName[15711:6706975] [Feedback] failed initializing core haptics engine for <_UIFeedbackCoreHapticsEngine: 0x282e115e0>: Error Domain=com.apple.CoreHaptics Code=-4810 "(null)"
(AppName is the name of the app)
After that it fails to run code in Task - I can see in the log that the Task is called but the code in it is never executed. The app only recovers after restart.
It may be relevant that the app runs background refresh couple of times before it happens.
Thank you for any help / suggestions.

Logging into GameCenter fails in iOS9 (Unity)

In a Unity project running on iPhones in iOS 9 I'm calling:
Social.localUser.Authenticate(ProcessAuthentication);
On a phone with all data cleared, this brings up Apple's dialogue to log into GameCenter. I enter an email address and password from an existing GameCenter test account. The dialogue seems to lock up for a few seconds. It then returns to the game, passing false (failure) to ProcessAuthentication.
When I try logging into the same account via the GameCenter settings menu, it brings up a Terms and Conditions screen that I wasn't getting in-game - I suspect that it's failing to bring it up and acting as though you refused to accept. If I complete the login process in settings I can run the game and GameCenter works fine.
This problem didn't occur in iOS 8.
Is this normal? Does anyone know if it can be fixed?
Edit:
Output message being printed:
Setting up 1 worker threads for Enlighten.
Thread->id: 40933000 -> priority: 1
2015-10-29 16:02:02:02.287 autowarriors[365:26287] plugin com.apple.GameCenterUI.GameCenterAuthenticateExension interrupted
2015-10-29 16:02:02:02.288 autowarriors[365:26233] plugin com.apple.GameCenterUI.GameCenterAuthenticateExension invalidated
2015-10-29 16:02:02:02.308 autowarriors[365:26220] viewServiceDidTerminateWithError:: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo=(Message=Service Connection Interrupted)
Failed to authenticate
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 64)
-> applicationWillResignActive()

Apple Push - didReceiveIncomingPushWithPayload not called - instead error: Failed sending message to client

I have an app that uses pushkit (voip push).
Most of the time the pushes get through. But when there is a lot of traffic, the pushes don't get through to the app.
I am in a state where I can somehow reproduce the error.
I used the extended logging from here:
https://developer.apple.com/library/ios/technotes/tn2265/_index.html
And I found this to examine the logging:
http://iosdevelopertips.com/core-services/debug-failed-push-messages-by-logging-apsd-process.html
Still, I got two different cases, where I just don't get further:
- In the apsd-log I get
Received message for enabled topic ...
and in the app the didReceiveIncomingPushWithPayload is not called. I produce a log entry right at the start of the function and do nothing special that could prevent the function from finishing.
- In the apsd-log I get
Stream error occurred ...
but do not find any other error messages, why this error occurs.
The Port seems ok
After restarting the app the pushes get through again.
EDIT:
The relevant error in the log file seems to be:
apsd[82]: Failed sending message to client: com.apple.telephonyutilities.callservicesdaemon.voip.push.development
There seems to be two types of cases: In some cases, which are reproducable with large traffic, reregistering the pushkit seems to help.
In other cases, which occur random, it simply does not. Restarting the app does not help here either.
All helps so far, is restarting the iphone.
EDIT:
I am still struggling with this problem.
In some cases I get a memory warning before the push seems to fail.
In other cases I get a xpc communication warning like this:
SpringBoard[43] <Warning>: Communications error: <OS_xpc_error: <error: 0x3b7ef614> { count = 1, contents =
"XPCErrorDescription" => <string: 0x3b7ef86c> { length = 22, contents = "Connection interrupted" }
}>
In some cases none of the above happens, but push still does not work.
EDIT:
In developer archive I found this very interesting thread, but still no answer:
https://devforums.apple.com/thread/257354?start=50&tstart=0
Does anybody know if there is a connection between xpc and push?
And is there a way to detect a xpc error in code?

Xcode leak tool stuck on MapkKit/CllocationManager Ios8

I have strange problem while using Xcode tools trying to find leaks in my App.
All my screens are working ok with the tool except the screen with mapView (e.g I have some registration screens and then the user proceed to MapView screen , in case the user logged in the Mapview screen opens). I think that the problem is somehow concerned to CllocationmManager
but I am not sure because the app simply stuck while using the leaking tool.
I receive the following Log from my Device :
timed[53] <Notice>: (Note ) CoreTime: Received time 10/21/2014 15:54:04±0.00 from "GPS"
timed[53] <Notice>: (Note ) CoreTime: Want active time in 3332.92min. Need active time in
8332.92min. Remaining retry interval: 0.000000min.
<Notice>: (Note ) CoreTime: Received time 10/21/2014 15:54:09±0.00 from "GPS"
<Notice>: (Note ) CoreTime: Want active time in 3332.82min. Need active time in 8332.82min.
CommCenter[69] <Error>: throttleCallBack(): Clearing throttle timer on context ID 0
CommCenter[69] <Error>: throttleCallBack(): Clearing throttle timer on context ID 1
CommCenter[69] <Error>: throttleCallBack(): Clearing throttle timer on context ID 2
<Error>: throttleCallBack(): Clearing throttle timer on context ID 3
timed[53] <Notice>: (Note ) CoreTime: Received time 10/21/2014 15:54:14±0.00 from "GPS"
timed[53] <Notice>: (Note ) CoreTime: Want active time in 3332.75min. Need active time in
CommCenter[69] <Error>: throttleCallBack(): Clearing throttle timer on context ID 0
CommCenter[69] <Error>: throttleCallBack(): Clearing throttle timer on context ID 1
CoreLocation: Discarding message for event 0 because of too many unprocessed messages
I think the last line is the most important according to that link: iOS5 What does “Discarding message for event 0 because of too many unprocessed messages” mean?
Yes, My locationManager run on main thread (it work pretty good in Debug mode and without it).
I also try in Simulator (it also stuck I think with some different reason but I need to test it mainly on device because my app Heavily depend on user location). I set every possible configuration to debug in my scheme.
I tried to restart the device.
I tried on iphone 5s and 4.
(I use Xcode6 Ios8 ).
Does anyone had some similar problem or an idea what can I try?
Thanks a lot.
In the end I found the problem. Well the problem was pretty stupid I believe not many people will ever have this kind of issue but i will post my silly mistake.
While I developed the app I included a lot of logs there (some response from the server) as the time passed I forgot to remove them (of course before the release I would ).
That what actually stuck the app when it was running using tools.
That the response I received from apple support:
As NSLog also writes on the main thread, it was blocking both the map display and the location manager.
One thing to keep in mind is, although NSLog is generally used for printing our debug information, that is not it’s real job.
If you look at the Foundation Framework Reference docs, NSLog is described as: Logs an error message to the Apple System Log facility.
Therefore it is a very heavyweight call, and effects the performance of apps a lot.
and indeed when I run "Time profiler" I noticed that percentage time of running Nslog in some method are quite heigh.......

Resources