Amplitude-iOS icon indicating copy to clipboard operation
Amplitude-iOS copied to clipboard

Failed to send events in widget extension

Open IlyaSirosh opened this issue 2 years ago • 2 comments

Hello, I have an issue with sending events from widget extension. I've tried following options:

  1. Updated to the latest version of SDK (from v4.10.0 to v8.17.2)
  2. Force events sending with Amplitude.instance(withName: "widgets").uploadEvents()
  3. Send events with API (batch operation) and wait for response before returning timeline in Provider.getTimeline(...)
  4. Also I've tried to use the newest SDK for Amplitude: Amplitude-Swift v1.1.0 -- it isn't support to be used in app extensions

Appreciate any help or advice

Expected Behavior

Event should be sent via SDK

Current Behavior

Getting error in console while SDK tries to send event: ERROR: Connection error:Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={_kCFStreamErrorCodeKey=57, NSUnderlyingError=0x147f0bf50 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={_kCFStreamErrorCodeKey=57, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <E4CEB02E-270B-420A-88F5-82F6A4AB6DFF>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <E4CEB02E-270B-420A-88F5-82F6A4AB6DFF>.<1>" ), NSLocalizedDescription=The network connection was lost., NSErrorFailingURLStringKey=https://api.amplitude.com/, NSErrorFailingURLKey=https://api.amplitude.com/, _kCFStreamErrorDomainKey=1}

Or with API calls:

Task <5EF7A32F-D407-41BE-A8E4-B38A9CC8A9A0>.<1> finished with error [18 446 744 073 709 550 619] Error Domain=NSURLErrorDomain Code=-997 UserInfo={NSErrorFailingURLStringKey=<private>, NSErrorFailingURLKey=<private>, _NSURLErrorRelatedURLSessionTaskErrorKey=<private>, _NSURLErrorFailingURLSessionTaskErrorKey=<private>, NSLocalizedDescription=<private>}

I have to mention that network conditions is actually fine and events can be successfully sent from application, but widget extension.

Possible Solution

Steps to Reproduce

  1. Install application
  2. Kill application (in order to run only widget extension process)
  3. Add widget (event is triggered on getting timeline)

Environment

  • SDK Version: v8.17.2, v4.10.0
  • Device: iPhone 14 pro
  • OS Version: iOS 17.0.2

IlyaSirosh avatar Nov 01 '23 16:11 IlyaSirosh

Hi @IlyaSirosh, thanks for choosing Amplitude.

Were you using the this batch API? I would suggest to use the HTTP V2 API which is the endpoint the Swift SDK is using.

Currently we don't support sending events in widget extension. I added a feature request label and put this to our backlog. But we don't have an ETA for this feature due to the high volume of support tickets. We can help to merge in if you have a PR to add this feature.

Hope it helps.

Mercy811 avatar Nov 06 '23 19:11 Mercy811

Hi @Mercy811, thank you for response and advice.

Indeed I've made a workaround with batch API and background URL session. Works fine.

IlyaSirosh avatar Nov 06 '23 21:11 IlyaSirosh