1
0

error_ios.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2022 The Ebiten Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package audio
  15. // #cgo CFLAGS: -x objective-c
  16. // #cgo LDFLAGS: -framework Foundation -framework UIKit
  17. //
  18. // #import <UIKit/UIKit.h>
  19. //
  20. // static UIApplicationState applicationState() {
  21. // if ([NSThread isMainThread]) {
  22. // return [[UIApplication sharedApplication] applicationState];
  23. // }
  24. // __block UIApplicationState state;
  25. // dispatch_sync(dispatch_get_main_queue(), ^{
  26. // state = [[UIApplication sharedApplication] applicationState];
  27. // });
  28. // return state;
  29. // }
  30. import "C"
  31. import (
  32. "fmt"
  33. )
  34. // addErrorInfo adds an additional information to the error when creating an audio context.
  35. // See also ebitengine/oto#93.
  36. func addErrorInfo(err error) error {
  37. if err == nil {
  38. return nil
  39. }
  40. var state string
  41. switch s := C.applicationState(); s {
  42. case C.UIApplicationStateActive:
  43. state = "active"
  44. case C.UIApplicationStateInactive:
  45. state = "inactive"
  46. case C.UIApplicationStateBackground:
  47. state = "background"
  48. default:
  49. state = fmt.Sprintf("UIApplicationState(%d)", s)
  50. }
  51. return fmt.Errorf("%w, application state: %s", err, state)
  52. }