LoadingView.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // LoadingView.m/Users/apple/Desktop/jiaPei/jiaPei/SearchBase.m
  3. //
  4. // Created by apple on 15/11/11.
  5. // Copyright (c) 2015年 JCZ. All rights reserved.
  6. //
  7. #import "LoadingView.h"
  8. #import "STButton.h"
  9. #import <AVFoundation/AVFoundation.h>
  10. static LoadingView* myView ;
  11. static NSMutableArray* msgArr;
  12. /**用来播放水滴声音的
  13. */
  14. static AVAudioPlayer* player;
  15. #define HUD_Frame [[UIScreen mainScreen] bounds]
  16. #define HUD_Size HUD_Frame.size
  17. @interface LoadingView()
  18. @end
  19. @implementation LoadingView
  20. +(void)makeVoice
  21. {
  22. NSString * path = [[NSBundle mainBundle] pathForResource:@"toast.wav" ofType:nil];
  23. NSFileManager* fm = [NSFileManager defaultManager];
  24. if (![fm fileExistsAtPath:path]) {
  25. return;
  26. }
  27. NSURL * url = [NSURL fileURLWithPath:path];
  28. player =[[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
  29. player.volume = 1;
  30. player.numberOfLoops =0;
  31. if (player.playing) {
  32. return;
  33. }
  34. [player play];
  35. }
  36. /**如果真机上遇到MSG无法消除的问题。可以考虑用数组保存label。然后遍历数组移除。
  37. 无法消除问题 --danson
  38. guide_icon7
  39. */
  40. +(void)showMsg:(NSString*)str
  41. {
  42. //如果是后台 就不在展示弹出框了
  43. if (myDelegate.isBackgroundTask) {
  44. return;
  45. }
  46. [self makeVoice];
  47. [MBProgressHUD showAutoMessage:str];
  48. }
  49. /**0是普通的警告。1是操作成功的
  50. */
  51. +(void)showMsg:(NSString *)str Style:(int)style
  52. {
  53. //如果是后台 就不在展示弹出框了
  54. if (myDelegate.isBackgroundTask) {
  55. return;
  56. }
  57. [self makeVoice];
  58. if (0 == style) {
  59. [MBProgressHUD showCustomIcon:@"mbp_error.png" Title:str ToView:nil];
  60. }else{
  61. [MBProgressHUD showCustomIcon:@"mbp_success.png" Title:str ToView:nil];
  62. }
  63. }
  64. @end
  65. #pragma mark -
  66. void ShowMsg(NSString* str)
  67. {
  68. [LoadingView showMsg:str];
  69. }
  70. void showMsgUnconnect(){
  71. [LoadingView showMsg:@"网络未连接"];
  72. }
  73. void showMsgLoginPls(){
  74. [LoadingView showMsg:@"请登录后操作"];
  75. }
  76. void ShowMsgUnOpen()
  77. {
  78. [LoadingView showMsg:@"暂未开放,敬请期待"];
  79. }
  80. void ShowMsgFailed()
  81. {
  82. [LoadingView showMsg:@"请求失败"];
  83. }
  84. void ShowMsgSuc()
  85. {
  86. [LoadingView showMsg:@"操作成功" Style:1];
  87. }
  88. #pragma mark 确定弹框提示
  89. void showMsgByAlert(UIViewController *vc,NSString *str)
  90. {
  91. if (![str isKindOfClass:[NSString class]]) {
  92. str = @"异常情况";
  93. }
  94. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:str preferredStyle:UIAlertControllerStyleAlert];
  95. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
  96. [vc presentViewController:alertFind animated:true completion:nil];
  97. }
  98. void showMsgByAlertWithSureBlock(UIViewController *vc,NSString *str,BlockTypeVo sureBlock)
  99. {
  100. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:str preferredStyle:UIAlertControllerStyleAlert];
  101. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  102. if (sureBlock) {
  103. sureBlock();
  104. }
  105. }]];
  106. [vc presentViewController:alertFind animated:true completion:nil];
  107. }