@@ -32,50 +32,64 @@ Include these frameworks in your project:
32
32
```
33
33
---
34
34
35
- ### Usage (.h)
35
+ ### Usage
36
36
37
- Import the * UIMediaAlertController.h* file into your project.< br >
38
- You must store the UIMediaAlertController as a property in your header class like so :
37
+ First, import the * UIMediaAlertController.h* file into the place you want to
38
+ use it :
39
39
``` objc
40
- // MyViewController.h
40
+ #import " UIMediaAlertController.h"
41
+ ```
42
+
43
+ There are 2 methods of using the UIMediaAlertController:
44
+ - Shared Instance
45
+ - Stored Property
46
+
47
+ The benefits of using the shared instance is that it's really simple to call,
48
+ and that the same UIMedia object is used throughout the app - unless you call:
49
+ [ UIMediaAlertController resetMedia] ;
50
+ For example:
51
+
52
+ ``` objc
53
+ [UIMediaAlertController presentWithType: MediaTypeImage picked:^{
54
+ // Retreive global media by using:
55
+ UIMedia * media = [ UIMediaAlertController media] ;
56
+ // Reset global media:
57
+ [ UIMediaAlertController resetMedia] ;
58
+ }] ;
59
+ ```
60
+
61
+ The other method, is storing the UIMediaAlertController property in your
62
+ header file *MyViewController.h* like so:
63
+
64
+ ```objc
65
+ // MyViewController.h
41
66
42
67
#import "UIMediaAlertController.h"
43
68
44
69
@implementation MyViewController : UIViewController
45
70
46
- @property (strong, nonatomic) UIMediaAlertController * mediaPicker ;
71
+ @property (strong, nonatomic) UIMediaAlertController *uimac ;
47
72
48
73
@end
49
- ```
50
74
51
- ### Usage (.m)
52
-
53
- UIMediaAlertController can be used from any class. If the * root* object is not a UIViewController, UIMediaAlertController will loop through responders and find the controller.<br >
75
+ ```
54
76
55
- Use ** MediaTypeImage** to pick an image<br >
56
- Use ** MediaTypeVideo** to pick a video<br >
77
+ * MyViewController.m* ":
57
78
58
79
``` objc
80
+
59
81
@implementation MyViewController
60
82
61
- - (void)viewDidLoad {
62
- [ super viewDidLoad] ;
63
- [ self showMediaController] ;
83
+ - (IBAction)chooseImageButtonClicked:(UIButton * )sender {
84
+ self.uimac = [[ UIMediaAlertController alloc] init] ;
85
+ [ self.uimac presentWithType: MediaTypeImage picked:^{
86
+ // get media:
87
+ UIMedia * media = self.uimac.media;
88
+ // resent media:
89
+ [ self.uimac resetMedia] ;
90
+ }] ;
64
91
}
65
92
66
- #pragma mark - Show Controller:
67
-
68
- - (void)showMediaController {
69
-
70
- if (!self.mediaPicker) {
71
- self.mediaPicker = [[UIMediaAlertController alloc] initWithRoot:self];
72
- }
73
-
74
- [self.mediaPicker presentMediaAlertWithType:MediaTypeImage picked:^(UIMedia *media) {
75
- // do something with media.image
76
- } removed:^(UIMedia *media) {
77
- // user removed image
78
- }];
79
-
80
- }
93
+ @end
94
+
81
95
```
0 commit comments