99import Foundation
1010#if os(macOS)
1111import AppKit
12+ #elseif os(watchOS)
13+ import WatchKit
1214#else
1315import UIKit
1416#endif
@@ -332,10 +334,36 @@ extension ConnectionManager {
332334// MARK: - FeedbackRepository
333335extension ConnectionManager {
334336 private func getPlatform( ) -> String {
337+ #if os(iOS) || os(tvOS)
335338 switch UIDevice . current. systemName. lowercased ( ) {
336339 case " ios " : return " ios "
337340 default : return " unknown "
338341 }
342+ #elseif os(macOS)
343+ return ProcessInfo . processInfo. operatingSystemVersionString. lowercased ( )
344+ #elseif os(watchOS)
345+ return WKInterfaceDevice . current ( ) . systemName. lowercased ( )
346+ #endif
347+ }
348+
349+ private func modelType( ) -> String {
350+ #if os(iOS) || os(tvOS)
351+ return UIDevice . current. modelType. rawValue
352+ #elseif os(macOS)
353+ return " unknown "
354+ #elseif os(watchOS)
355+ return WKInterfaceDevice . current ( ) . model
356+ #endif
357+ }
358+
359+ private func systemVersion( ) -> String {
360+ #if os(iOS) || os(tvOS)
361+ return UIDevice . current. systemVersion
362+ #elseif os(macOS)
363+ return " unknown "
364+ #elseif os(watchOS)
365+ return WKInterfaceDevice . current ( ) . systemVersion
366+ #endif
339367 }
340368
341369 func provideFeedback( _ feedback: Feedback , completion: @escaping Completion < Void > ) {
@@ -346,19 +374,21 @@ extension ConnectionManager {
346374 urlRequest. allHTTPHeaderFields = defaultHeaders
347375 urlRequest. setValue ( " multipart/form-data; boundary= \( boundary) " , forHTTPHeaderField: " Content-Type " )
348376
349- let data = MultipartBuilder ( boundary: boundary)
377+ let builder = MultipartBuilder ( boundary: boundary)
350378 . append ( name: " type " , value: feedback. type. rawValue)
351379 . append ( name: " platform " , value: getPlatform ( ) )
352- . append ( name: " os " , value: UIDevice . current . systemVersion)
353- . append ( name: " device " , value: UIDevice . current . modelType. rawValue )
380+ . append ( name: " os " , value: systemVersion ( ) )
381+ . append ( name: " device " , value: modelType ( ) )
354382 . append ( name: " app_version " , value: feedback. appVersion)
355383 . append ( name: " name " , value: feedback. name)
356384 . append ( name: " email " , value: feedback. email)
357385 . append ( name: " message " , value: feedback. message)
358- . append ( name: " image " , image: feedback. image, jpegQuality: 0.7 )
359- . build ( )
386+
387+ #if canImport(UIKit)
388+ builder. append ( name: " image " , image: feedback. image, jpegQuality: 0.7 )
389+ #endif
360390
361- session. uploadTask ( with: urlRequest, from: data , completionHandler: { _, _, error in
391+ session. uploadTask ( with: urlRequest, from: builder . build ( ) , completionHandler: { _, _, error in
362392 if let error = error {
363393 completion ( . failure( error) )
364394 } else {
0 commit comments