@@ -16,6 +16,27 @@ + (AudioShare*) sharedInstance {
16
16
return a;
17
17
}
18
18
19
+ + (void )showAlertController : (UIAlertController*)alertController {
20
+ UIViewController *presentingViewController = [[[UIApplication sharedApplication ] delegate ] window ].rootViewController ;
21
+
22
+ while (presentingViewController.presentedViewController != nil ) {
23
+ presentingViewController = presentingViewController.presentedViewController ;
24
+ }
25
+
26
+ [presentingViewController presentViewController: alertController animated: YES completion: nil ];
27
+ }
28
+
29
+ + (void )openURL : (NSURL *)URL {
30
+ UIApplication *application = [UIApplication sharedApplication ];
31
+
32
+ if ([application respondsToSelector: @selector (openURL:options:completionHandler: )]) {
33
+ [application openURL: URL options: @{}
34
+ completionHandler: nil ];
35
+ } else {
36
+ [application openURL: URL];
37
+ }
38
+ }
39
+
19
40
- (NSString *)escapeString : (NSString *)string {
20
41
NSString *s = [string stringByAddingPercentEncodingWithAllowedCharacters:
21
42
[NSCharacterSet URLQueryAllowedCharacterSet ]];
@@ -32,23 +53,9 @@ - (BOOL)addSoundFromData:(NSData*)data withName:(NSString*)name {
32
53
33
54
UIAlertAction *okAction = [UIAlertAction actionWithTitle: NSLocalizedString(@" OK" , @" OK action" )
34
55
style: UIAlertActionStyleDefault
35
- handler: ^(UIAlertAction *action)
36
- {
37
- NSLog (@" OK action" );
38
- }];
39
-
56
+ handler: ^(UIAlertAction *action){}];
40
57
[alertController addAction: okAction];
41
-
42
- id rootViewController = [UIApplication sharedApplication ].delegate .window .rootViewController ;
43
- if ([rootViewController isKindOfClass: [UINavigationController class ]])
44
- {
45
- rootViewController = ((UINavigationController *)rootViewController).viewControllers .firstObject ;
46
- }
47
- if ([rootViewController isKindOfClass: [UITabBarController class ]])
48
- {
49
- rootViewController = ((UITabBarController *)rootViewController).selectedViewController ;
50
- }
51
- [rootViewController presentViewController: alertController animated: YES completion: nil ];
58
+ [AudioShare showAlertController: alertController];
52
59
53
60
return NO ;
54
61
}
@@ -75,36 +82,24 @@ - (BOOL)addSoundFromData:(NSData*)data withName:(NSString*)name {
75
82
76
83
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle: NSLocalizedString(@" Cancel" , @" Cancel action" )
77
84
style: UIAlertActionStyleCancel
78
- handler: ^(UIAlertAction *action)
79
- {
80
- NSLog (@" Cancel action" );
81
- }];
85
+ handler: ^(UIAlertAction *action){}];
82
86
83
87
UIAlertAction *okAction = [UIAlertAction actionWithTitle: NSLocalizedString(@" OK" , @" OK action" )
84
88
style: UIAlertActionStyleDefault
85
89
handler: ^(UIAlertAction *action)
86
90
{
87
- NSLog (@" OK action" );
88
- [self openScheme: @" http://kymatica.com/audioshare/download.php" ];
91
+ [AudioShare openURL: [NSURL URLWithString: @" http://kymatica.com/audioshare/download.php" ]];
89
92
}];
90
93
91
94
[alertController addAction: cancelAction];
92
95
[alertController addAction: okAction];
93
96
94
- id rootViewController = [UIApplication sharedApplication ].delegate .window .rootViewController ;
95
- if ([rootViewController isKindOfClass: [UINavigationController class ]])
96
- {
97
- rootViewController = ((UINavigationController *)rootViewController).viewControllers .firstObject ;
98
- }
99
- if ([rootViewController isKindOfClass: [UITabBarController class ]])
100
- {
101
- rootViewController = ((UITabBarController *)rootViewController).selectedViewController ;
102
- }
103
- [rootViewController presentViewController: alertController animated: YES completion: nil ];
97
+ [AudioShare showAlertController: alertController];
104
98
105
99
return NO ;
106
100
}
107
- return [[UIApplication sharedApplication ] openURL: asURL];
101
+ [AudioShare openURL: asURL];
102
+ return YES ;
108
103
}
109
104
110
105
- (BOOL )addSoundFromURL : (NSURL *)url withName : (NSString *)name {
@@ -121,24 +116,12 @@ - (BOOL)addSoundFromPath:(NSString*)path withName:(NSString*)name {
121
116
122
117
UIAlertAction *okAction = [UIAlertAction actionWithTitle: NSLocalizedString(@" OK" , @" OK action" )
123
118
style: UIAlertActionStyleDefault
124
- handler: ^(UIAlertAction *action)
125
- {
126
- NSLog (@" OK action" );
127
- }];
119
+ handler: ^(UIAlertAction *action){}];
128
120
129
121
[alertController addAction: okAction];
130
122
131
- id rootViewController = [UIApplication sharedApplication ].delegate .window .rootViewController ;
132
- if ([rootViewController isKindOfClass: [UINavigationController class ]])
133
- {
134
- rootViewController = ((UINavigationController *)rootViewController).viewControllers .firstObject ;
135
- }
136
- if ([rootViewController isKindOfClass: [UITabBarController class ]])
137
- {
138
- rootViewController = ((UITabBarController *)rootViewController).selectedViewController ;
139
- }
140
- [rootViewController presentViewController: alertController animated: YES completion: nil ];
141
-
123
+ [AudioShare showAlertController: alertController];
124
+
142
125
return NO ;
143
126
}
144
127
NSData *dataFile = [NSData dataWithContentsOfURL: [NSURL fileURLWithPath: path] options: NSDataReadingMappedIfSafe error: NULL ];
@@ -175,24 +158,12 @@ - (BOOL)initiateSoundImport {
175
158
176
159
UIAlertAction *okAction = [UIAlertAction actionWithTitle: NSLocalizedString(@" OK" , @" OK action" )
177
160
style: UIAlertActionStyleDefault
178
- handler: ^(UIAlertAction *action)
179
- {
180
- NSLog (@" OK action" );
181
- }];
161
+ handler: ^(UIAlertAction *action){}];
182
162
183
163
[alertController addAction: okAction];
184
164
185
- id rootViewController = [UIApplication sharedApplication ].delegate .window .rootViewController ;
186
- if ([rootViewController isKindOfClass: [UINavigationController class ]])
187
- {
188
- rootViewController = ((UINavigationController *)rootViewController).viewControllers .firstObject ;
189
- }
190
- if ([rootViewController isKindOfClass: [UITabBarController class ]])
191
- {
192
- rootViewController = ((UITabBarController *)rootViewController).selectedViewController ;
193
- }
194
- [rootViewController presentViewController: alertController animated: YES completion: nil ];
195
-
165
+ [AudioShare showAlertController: alertController];
166
+
196
167
return NO ;
197
168
}
198
169
NSURL *asURL = [NSURL URLWithString: [NSString stringWithFormat: @" audioshare.import://%@ " ,callback]];
@@ -208,41 +179,27 @@ - (BOOL)initiateSoundImport {
208
179
209
180
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle: NSLocalizedString(@" Cancel" , @" Cancel action" )
210
181
style: UIAlertActionStyleCancel
211
- handler: ^(UIAlertAction *action)
212
- {
213
- NSLog (@" Cancel action" );
214
- }];
182
+ handler: ^(UIAlertAction *action){}];
215
183
216
184
UIAlertAction *okAction = [UIAlertAction actionWithTitle: NSLocalizedString(@" OK" , @" OK action" )
217
185
style: UIAlertActionStyleDefault
218
186
handler: ^(UIAlertAction *action)
219
187
{
220
- NSLog (@" OK action" );
221
- // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://kymatica.com/audioshare/download.php"]];
222
- [self openScheme: @" http://kymatica.com/audioshare/download.php" ];
188
+ [AudioShare openURL: [NSURL URLWithString: @" http://kymatica.com/audioshare/download.php" ]];
223
189
}];
224
190
225
191
[alertController addAction: cancelAction];
226
192
[alertController addAction: okAction];
227
-
228
- id rootViewController = [UIApplication sharedApplication ].delegate .window .rootViewController ;
229
- if ([rootViewController isKindOfClass: [UINavigationController class ]])
230
- {
231
- rootViewController = ((UINavigationController *)rootViewController).viewControllers .firstObject ;
232
- }
233
- if ([rootViewController isKindOfClass: [UITabBarController class ]])
234
- {
235
- rootViewController = ((UITabBarController *)rootViewController).selectedViewController ;
236
- }
237
- [rootViewController presentViewController: alertController animated: YES completion: nil ];
193
+
194
+ [AudioShare showAlertController: alertController];
238
195
239
196
if (hasAudio)
240
197
asURL = [NSURL URLWithString: [callback stringByAppendingString: @" ://PastedAudio" ]];
241
198
else
242
199
return NO ;
243
200
}
244
-
245
- return [[UIApplication sharedApplication ] openURL: asURL] ;
201
+ [AudioShare openURL: asURL];
202
+ return YES ;
246
203
}
247
204
248
205
- (NSString *)writeSoundImport : (NSString *)filename {
@@ -294,24 +251,12 @@ - (BOOL)checkPendingImport:(NSURL *)url withBlock:(AudioShareImportBlock)block {
294
251
295
252
UIAlertAction *okAction = [UIAlertAction actionWithTitle: NSLocalizedString(@" OK" , @" OK action" )
296
253
style: UIAlertActionStyleDefault
297
- handler: ^(UIAlertAction *action)
298
- {
299
- NSLog (@" OK action" );
300
- }];
254
+ handler: ^(UIAlertAction *action){}];
301
255
302
256
[alertController addAction: okAction];
303
257
304
- id rootViewController = [UIApplication sharedApplication ].delegate .window .rootViewController ;
305
- if ([rootViewController isKindOfClass: [UINavigationController class ]])
306
- {
307
- rootViewController = ((UINavigationController *)rootViewController).viewControllers .firstObject ;
308
- }
309
- if ([rootViewController isKindOfClass: [UITabBarController class ]])
310
- {
311
- rootViewController = ((UITabBarController *)rootViewController).selectedViewController ;
312
- }
313
- [rootViewController presentViewController: alertController animated: YES completion: nil ];
314
-
258
+ [AudioShare showAlertController: alertController];
259
+
315
260
return NO ;
316
261
}
317
262
block (path);
@@ -337,24 +282,11 @@ + (void)appDidLaunch {
337
282
338
283
UIAlertAction *okAction = [UIAlertAction actionWithTitle: NSLocalizedString(@" OK" , @" OK action" )
339
284
style: UIAlertActionStyleDefault
340
- handler: ^(UIAlertAction *action)
341
- {
342
- NSLog (@" OK action" );
343
- }];
285
+ handler: ^(UIAlertAction *action){}];
344
286
345
287
[alertController addAction: okAction];
346
288
347
- id rootViewController = [UIApplication sharedApplication ].delegate .window .rootViewController ;
348
- if ([rootViewController isKindOfClass: [UINavigationController class ]])
349
- {
350
- rootViewController = ((UINavigationController *)rootViewController).viewControllers .firstObject ;
351
- }
352
- if ([rootViewController isKindOfClass: [UITabBarController class ]])
353
- {
354
- rootViewController = ((UITabBarController *)rootViewController).selectedViewController ;
355
- }
356
- [rootViewController presentViewController: alertController animated: YES completion: nil ];
357
-
289
+ [AudioShare showAlertController: alertController];
358
290
}
359
291
}
360
292
@@ -405,19 +337,4 @@ + (NSString*)findFileType:(NSString*)path {
405
337
}
406
338
}
407
339
408
- - (void )openScheme : (NSString *)scheme {
409
- UIApplication *application = [UIApplication sharedApplication ];
410
- NSURL *URL = [NSURL URLWithString: scheme];
411
-
412
- if ([application respondsToSelector: @selector (openURL:options:completionHandler: )]) {
413
- [application openURL: URL options: @{}
414
- completionHandler: ^(BOOL success) {
415
- NSLog (@" Open %@ : %d " ,scheme,success);
416
- }];
417
- } else {
418
- BOOL success = [application openURL: URL];
419
- NSLog (@" Open %@ : %d " ,scheme,success);
420
- }
421
- }
422
-
423
340
@end
0 commit comments