Skip to content

Commit b32d17a

Browse files
authored
Update README.md
1 parent c539f6a commit b32d17a

File tree

1 file changed

+43
-29
lines changed

1 file changed

+43
-29
lines changed

README.md

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,50 +32,64 @@ Include these frameworks in your project:
3232
```
3333
---
3434

35-
### Usage (.h)
35+
### Usage
3636

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:
3939
```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
4166
4267
#import "UIMediaAlertController.h"
4368
4469
@implementation MyViewController : UIViewController
4570
46-
@property (strong, nonatomic) UIMediaAlertController *mediaPicker;
71+
@property (strong, nonatomic) UIMediaAlertController *uimac;
4772
4873
@end
49-
```
5074
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+
```
5476

55-
Use **MediaTypeImage** to pick an image<br>
56-
Use **MediaTypeVideo** to pick a video<br>
77+
*MyViewController.m*":
5778

5879
```objc
80+
5981
@implementation MyViewController
6082

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+
}];
6491
}
6592

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+
8195
```

0 commit comments

Comments
 (0)