UIImagePickerController to show only videos - objective-c

Is it possible to have the UIImagePickerController only show the videos on the phone and not both videos and photos? Thanks.

Set the mediaType property of the UIImagePickerController.
//Example from documentation
myImagePickerController.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
or to simplify the documentation's example with newer syntax:
myImagePickerController.mediaTypes = #[kUTTypeMovie];
More information and guidance is available in the documentation.

Related

Good Design for Contact Apps - Custom Table Cell Layout

Note: After reading, please edit title if not appropriate.
I'm just amateur in iOS. I practicing the objective-C with self-task and I'm trying to create a Contact Apps without any backend.
Problem:
In my app, I would like to display name and image in a cell. How can I achieve this?. I've already tried by adding to the sub view, the label(For Name) and image view (For Image) to a cell. But, it gives more conditional check for each of the different contact types. Like...
//In cellForRowAtIndexPath,
UILabel *lblForCell=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
lblForCell.text=[arrForMyContacts objectAtIndex:indexPath.row];
[tblCellForContactTable.contentView addSubview:lblForCell];
if([lblForCell.text isEqual:#"Mom"]){
UIImageView *imgForContact=[[UIImageView alloc] initWithFrame:CGRectMake(200, 10, 60, 7)];
imgForContact.image=[UIImage imageNamed:#"Mom.png"];
[tblCellForContactTable.contentView addSubview: imgForContact];
}
//likewise condition increased for dad, bro etc...- bad design, Correct?
So tell me its there any other way to decrease condition.
There are several ways to do. First create an array of Dictionary. Something like this
NSMutableArray *contacts = [[NSMutableArray alloc] init];
NSDictionary *mom = [NSDictionary dictionaryWithObjectsAndKeys:#"MOM", #"Name",
#"mom.png", #"imageName",
nil];
NSDictionary *dad = [NSDictionary dictionaryWithObjectsAndKeys:#"DAD", #"Name",
#"dad.png", #"imageName",
nil];
NSDictionary *son = [NSDictionary dictionaryWithObjectsAndKeys:#"SON", #"Name",
#"son.png", #"imageName",
nil];
[contacts addObjectsFromArray:#[mom, dad, son]];
Second create a custom UIView class where you can render this dictionary with init method something like this
-(id)initWithContactInfo:(NSDictionary *)contactInfo;
Third at the tableView
//In cellForRowAtIndexPath,
NSDictionary *contact = [contacts objectAtIndex:indexpath.row];
MYCustomView *contactCell = [[MYCustomView alloc] initWithContactInfo:contact];
[cell.contentView addSubView:contactCell];
Making a custom View gives you flexibility of customizing your view for particular cell.
I hope it helps . Best of luck

How to add NSArray in a video with AVMutableMetadataItem?

I am trying to save video with custom NSArray metadata relevant for my app and trying to retrieve it when the user selects that video from the library.
I'm using the AVAssetExportSession function to add metadata.
I used the sample code AVMovieExporter, and I tried to change locationMetadata.value
http://developer.apple.com/library/ios/#samplecode/AVMovieExporter/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011364
AVMutableMetadataItem *locationMetadata = [[AVMutableMetadataItem alloc] init];
locationMetadata.key = AVMetadataCommonKeyLocation;
locationMetadata.keySpace = AVMetadataKeySpaceCommon;
locationMetadata.locale = self.locale;
//locationMetadata.value = [NSString stringWithFormat:#"%+08.4lf%+09.4lf", self.location.coordinate.latitude, self.location.coordinate.longitude];
locationMetadata.value = [[NSArray alloc] initWithObjects: #"abc", #123,nil];
If I use value as a NSString there is no problem, but if I use a NSArray, it doesn't save the metadata.
Where is the problem?
Apple's documentation states:
NSString *const AVMetadataCommonKeyLocation;
I understand that to say the value must be a string, and cannot be an array.

Limit Social Sharing Options and Set Custom Message for Each Service

I am about to implement a share button calling the default modal sharing activities view.
Here's what I got so far.
NSString *textToShare = [NSString stringWithFormat:#"Looking forward to meet you at %#",[eventItemObject eventName]];;
NSURL *url = [eventItemObject eventWebsiteURL];
NSArray *activityItems = [[NSArray alloc] initWithObjects:textToShare,url,nil];
UIActivity *activity = [[UIActivity alloc] init];
NSArray *applicationActivities = [[NSArray alloc] initWithObjects:activity, nil];
UIActivityViewController *activityVC =
[[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
[self presentViewController:activityVC animated:YES completion:nil];
This is called when I press the sharing button.
Challenge:
Limit the sharing option to e.g. Facebook, Twitter, Mail (It now also shows Copy to Clipboard and Weibo)
Assign custom sharing messages/strings for each sharing method. (now the textToShare string is used for all services)
After some research I think this can be done with the new SLComposeViewController (in iOS6), but I am not sure where/how to call it correctly. Any practical advice or example is appreciated!
You can specify which activities not to show be using the activityViewController's setExcludedActivityTypes:. Example:
[activityVC setExcludedActivityTypes:[NSArray arrayWithObjects:
UIActivityTypeMessage,UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,UIActivityTypePostToWeibo,
UIActivityTypePrint,UIActivityTypeSaveToCameraRoll,
nil]];
As far as sending specific content to different activities goes, I've spent the last day or so trying to figure out how to do that. I'll update this post to include this info if/when I figure it out.

Problem with memory management

Here is a sample code, i am trying to import contacts for the iphone to my app.
-(IBAction)import_Clicked:(id)sender{
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init]; //leaking here
picker.peoplePickerDelegate = self;
// Display only a person's phone, email, and birthdate
NSArray *displayedItems = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonPhoneProperty],
[NSNumber numberWithInt:kABPersonEmailProperty],
[NSNumber numberWithInt:kABPersonBirthdayProperty], nil];
picker.displayedProperties = displayedItems;
[self presentModalViewController:picker animated:YES];
[picker release];}
i ran this on instruments and it shows me 100% leak at line where i alloc abpeoplepickernavigationcontroller. i realsed it after persentmodalviewcontroller. where else could i go wrong.
Any Help , Please.....
There seems to be a strange SDK bug at large here... Have a read of the official Apple dev forums here for more information and a solution.
Strange, that doesn't looks like a leak to me, heard that Instruments (rarely) report false leaks.
EDIT: forget what follows and read bbum comment instead :)
Could you please try removing [picker release] and then use autorelease instead :
BPeoplePickerNavigationController *picker = [[[ABPeoplePickerNavigationController alloc] init] autorelease];
Then see if instruments still report a leak? If not, keep your original code and ignore that false alert...
That is almost the same but using NSAutoReleasePool might change Instruments behavior.
Please also note that explicitly releasing like you did is a more cleaner approach than autoreleasing.

Detect if NSString contains a URL and generate a "link" to open inside the app a Safari View

I have am reading a twitter feed in my iPhone application and can do it correctly, but I'd like to evolve it in a way to detect if the whole NSString contains any URL or URLs and create a "link" that will open a UIWebView within the same application.
Can you guide me on how to perform this task?
-(void) setTextTwitter:(NSString *)text WithDate:(NSString*)date
{
[text retain];
[textTwitter release], textTwitter = nil;
textTwitter = text;
[date retain];
[dateTwitter release], dateTwitter = nil;
dateTwitter = date;
[self setNeedsDisplay];
}
Check out Craig Hockenberry's IFTweetLabel, which can be found here.
Or you can use the label provided by Three20 library, which can be found here.
Or the simplest solution: use UIWebView with dataDetectorTypes set to UIDataDetectorTypeLink.
Cheers, Paul