Currently I am trying to create some shortcuts for my iOS 17 app. The AppIntent looks like this:
class PostClass{
public init() {
let url = URL(string: "http://myurl")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
struct Message: Encodable {
let device_type: String
}
let message = Message(
device_type: "device"
)
let data = try! JSONEncoder().encode(message)
request.httpBody = data
request.setValue(
"application/json",
forHTTPHeaderField: "Content-Type"
)
self.request = request
}
}
var activateDevice = PostClass()
@available(iOS 17, *)
struct ActivateIntent: AppIntent {
static let title: LocalizedStringResource = "Activate"
func perform() async throws -> some IntentResult {
let task = URLSession.shared.dataTask(with: activateDevice.request) { data, response, error in
let statusCode = (response as! HTTPURLResponse).statusCode
if statusCode == 200 {
print("SUCCESS")
} else {
print("FAILURE")
}
}
task.resume()
return .result()
}
}
Unfortunately, the shortcut throws an error after every second execution. I looked into the ips-file and saw the following traceback:
Thread 2 Crashed:
0 Runner 0x1028ddd30 closure #1 in ActivateIntent.perform() + 388
1 CFNetwork 0x1a6f39248 0x1a6f2a000 + 62024
2 CFNetwork 0x1a6f57210 0x1a6f2a000 + 184848
3 libdispatch.dylib 0x1adced13c _dispatch_call_block_and_release + 32
4 libdispatch.dylib 0x1adceedd4 _dispatch_client_callout + 20
5 libdispatch.dylib 0x1adcf6400 _dispatch_lane_serial_drain + 748
6 libdispatch.dylib 0x1adcf6f64 _dispatch_lane_invoke + 432
7 libdispatch.dylib 0x1add01cb4 _dispatch_root_queue_drain_deferred_wlh + 288
8 libdispatch.dylib 0x1add01528 _dispatch_workloop_worker_thread + 404
9 libsystem_pthread.dylib 0x201dd4f20 _pthread_wqthread + 288
10 libsystem_pthread.dylib 0x201dd4fc0 start_wqthread + 8
Is there any way to locate the error with these information? Has it something to do with the fact that my code is not thread-safe? Or is there any internal bug?
Grateful for any help, thanks in advance!