WKInterfaceController+VLCConnectionAlert.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*****************************************************************************
  2. * WKInterfaceController+VLCConnectionAlert.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Author: Tobias Conradi <videolan # tobias-conradi.de>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. #import "WKInterfaceController+VLCConnectionAlert.h"
  13. #import <WatchConnectivity/WatchConnectivity.h>
  14. @implementation WKInterfaceController (VLCConnectionAlert)
  15. - (void)vlc_performBlockIfSessionReachable:(void(^__nullable)())reachableBlock showUnreachableAlert:(BOOL)unreachableAlert {
  16. [self vlc_performBlockIfSessionReachable:reachableBlock showUnreachableAlert:unreachableAlert alertOKAction:nil];
  17. }
  18. - (void)vlc_performBlockIfSessionReachable:(void(^__nullable)())reachableBlock showUnreachableAlert:(BOOL)unreachableAlert alertOKAction:(void (^ _Nullable)())okActionBlock {
  19. BOOL isReachable = [[WCSession defaultSession] isReachable];
  20. if (!isReachable && unreachableAlert) {
  21. WKAlertAction *okAction = [WKAlertAction actionWithTitle:NSLocalizedString(@"BUTTON_OK", nil)
  22. style:WKAlertActionStyleDefault
  23. handler:^{
  24. if (okActionBlock) {
  25. okActionBlock();
  26. }
  27. }];
  28. [self presentAlertControllerWithTitle:NSLocalizedString(@"NOT_CONNECTED_TO_PHONE_TITLE", nil)
  29. message:NSLocalizedString(@"NOT_CONNECTED_TO_PHONE_MESSAGE", nil)
  30. preferredStyle:WKAlertControllerStyleAlert
  31. actions:@[okAction]];
  32. return;
  33. } else if (isReachable && reachableBlock) {
  34. reachableBlock();
  35. }
  36. }
  37. @end