Customize scanner camera view zbar ios sdk - zbar-sdk

Is there a way to customize zbar sdk camera view.
I used below code to add the scanner.
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
[self presentViewController:reader animated:YES completion:nil];
I wanted to do like this kind of screen. link

Related

EXC_BAD_ACCESS when movie played the second time

I am using mpmovieplayercontroller to play a movie in my game. When the user taps the screen I run a method that replaces the current layer containing the movie with the game main menu. It works fine the first time, but when I try to play the video the second time from the main menu I get an EXC_BAD_ACCESS error on the line
int retVal = UIApplicationMain(argc, argv, nil, #"AppController");
in the main.m.
Please find the relevant code below.
-(void)playVideo {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"movie" ofType:#"mp4"]];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.repeatMode = MPMovieRepeatModeOne;
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
if ([moviePlayer respondsToSelector:#selector(setFullscreen:animated:)]) {
// Use the new 3.2 style API
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.shouldAutoplay = YES;
// This does blows up in cocos2d, so we'll resize manually
[moviePlayer setFullscreen:YES animated:YES];
CGSize winSize = [[CCDirector sharedDirector] winSize];
moviePlayer.view.frame = CGRectMake(0, 0, winSize.width, winSize.height); //width and height are swapped after rotation
[[[CCDirector sharedDirector] view] addSubview:moviePlayer.view ];
[moviePlayer play];
UITapGestureRecognizer * tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap:)];
tapGestureRecognizer.delegate = (id)self;
tapGestureRecognizer.numberOfTapsRequired = 1;
[[[CCDirector sharedDirector] view] addGestureRecognizer:tapGestureRecognizer];
[tapGestureRecognizer release];
} else {
// Use the old 2.0 style API
moviePlayer.controlStyle = MPMovieControlStyleNone;
[moviePlayer play];
}
}
- (void)handleTap:(UITapGestureRecognizer *)gesture {
[moviePlayer stop];
[[MenuManager sharedMenuManager] runMenu:kMMenuLayer];
}
// this enables you to handle multiple recognizers on single view
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
-(void)moviePlayBackDidFinish:(NSNotification*)notification {
moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
// If the moviePlayer.view was added to the openGL view, it needs to be removed
if ([moviePlayer respondsToSelector:#selector(setFullscreen:animated:)]) {
[moviePlayer.view removeFromSuperview];
CCLOG(#"this block is okay");
}
[moviePlayer release];
}
Please help.
The reason why you're getting the message is sent to a deallocated instance is because you've not removed the tapGestureRecognizer from the view. I believe your MenuManager singleton replaces the current layer with another, but since the tapGestureRecognizer is still part of the view it will try to access the handleTap, which by this time is deallocated. Add the following line before singleton call in handleTap.
[[[CCDirector sharedDirector] view] removeGestureRecognizer:tapGestureRecognizer];

Xcode social media sharing button

Is there any built-in api/code for Xcode that allow the app to detect what other social media apps installed in the iphone/ipad/ipod touch to populate out the sharing features?
I was told that Android has such capability, so does iOS have it too?
Twitter integration is built into iOS 5, check this link http://developer.apple.com/library/ios/documentation/Twitter/Reference/TWTweetSheetViewControllerClassRef/Reference/Reference.html
For Facebook you need to use the Facebook SDK, check here http://developers.facebook.com/docs/reference/iossdk/
Alternatively you could try ShareKit... http://getsharekit.com/
Or GetSocialize...
http://www.GetSocialize.com/
Both of these offer drop in functionality.
- (IBAction) shareHasTapped: (id)sender {
NSString *texttoshare = #"text to share";
// UIImage *imagetoshare = [UIImage imageNamed:#"beck.png"];
NSArray *activityItems = #[texttoshare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes =#[UIActivityTypeCopyToPasteboard, UIActivityTypePostToWeibo, UIActivityTypePostToTwitter, UIActivityTypePostToWeibo];
[self presentViewController:activityVC animated:TRUE completion:nil];
}
Share Image Social Network Using UIActivityViewController:
-(void)shareimage
{
NSArray *objectsToShare = #[_s_image];
UIActivityViewController * avc = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
avc.excludedActivityTypes=#[UIActivityTypePostToTwitter];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[self presentViewController:avc animated:YES completion:nil];
}
else
{
UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:avc];
[popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}

MPMoviePlayerController view orientation differs on iphone 3g and 4g

I'm trying to play fullscreen landscape video in .m4v format on iPhone using MPMoviePlayerController in my cocos2d game. On 4g device everything works well, but on 3g the video has screen dimensions but vertical orientation, so I can only see the left side of the movie. I'm not sure if the problem is with MPMoviePlayerController or with cocos2d gl view. Here's my code:
NSString *url = [[NSBundle mainBundle] pathForResource:#"intro" ofType:#"m4v"];
player = [[[MPMoviePlayerController alloc] initWithContentURL: [NSURL fileURLWithPath:url]] retain];
[player.view setFrame: [[CCDirector sharedDirector] openGLView].bounds];
if ([player respondsToSelector:#selector(setFullscreen:animated:)]) {
// Use the new 3.2 style API
player.controlStyle = MPMovieControlStyleNone;
player.shouldAutoplay = YES;
CGSize winSize = [[CCDirector sharedDirector] winSize];
CGRect rScreen;
rScreen.origin.x = 0;
rScreen.origin.y = 0;
rScreen.size.width = winSize.width;
rScreen.size.height = winSize.height;
player.view.frame = rScreen;
} else {
// Use the old 2.0 style API
player.movieControlMode = MPMovieControlModeHidden;
}
[[[CCDirector sharedDirector] openGLView] addSubview:player.view];
[player play];
How to make video play well on 3g device? Thanks for your help!

iPad2 Camera code same as iPhone4?

I am making an app for the iPad and want to be able to use the iPad 2 camera if available. Is the code to load the iPad camera the same as for the iPhone 4? I have this same code working on the iPhone version of this app, but do not have an iPad 2 to test with and simulator can't help me with the camera. Below is what I have to determine if camera is available and then to load camera or load library in popup
Basically I just need to know if the line below is supported by the iPad 2 camera or do I need to use something else?
[self presentModalViewController:imagePickerController animated:YES];
I want camera to be full screen and not in a popup.
- (IBAction) takePhoto:(id)sender {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
imagePickerController = [[UIImagePickerController alloc] init];
[imagePickerController setDelegate:self];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
imageView.contentMode = UIViewContentModeScaleAspectFit;
[self presentModalViewController:imagePickerController animated:YES];
} else {
imagePickerController = [[UIImagePickerController alloc] init];
[imagePickerController setDelegate:self];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
imageView.contentMode = UIViewContentModeScaleAspectFit;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
[popover setDelegate:self];
[popover presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
}
Yes this works, for sure if self is a UINavigationController. I know this because I do the same in my app. I'm not sure for other UIViewControllers, but it stands to reason that it will also work.

iPhone video recording: "cameraCaptureMode 1 not available because mediaTypes does contain public.movie"

I tried to record a video.
The message I got is from the following code on the device:
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsEditing = YES;
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
imagePickerController.delegate = self;
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
Any ideas? I think it should be really easy to take a video. When I start the "Camera" app of the phone I have the choice between video and picture. Shouldn't it be available for my app also?
The problem was the way I was trying to set the mode to video mode.
Instead of using this:
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
I changed it to this:
imagePickerController.mediaTypes =
[NSArray arrayWithObject:(NSString *)kUTTypeMovie];
and it worked.
For Swift 3.0, you have to add below line to support both photo and video
import MobileCoreServices
imagePicker.mediaTypes = [kUTTypeMovie as String, kUTTypeImage as String]
Add to above answers, as Micko mentioned, you need to add MobileCoreServices.framework in your project and ref it in your imagePickerController.
For those who want to have a switch under the toolbar in your image shooting view, just set the mediaTypes delegate as follows:
imagePC.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, (NSString *)kUTTypeImage, nil];
Now, you can have both still image taking and video taking, enjoy!!!
Xcode 9 - Swift 4.x:
Take care about the order of these statements:
imagePickerController.mediaTypes = [kUTTypeMovie as String]
imagePickerController.cameraCaptureMode = .video
And you remember to add to info.plist:
And if you are working with Swift, then you will have to add MobileCoreServices.framework as well as the following Module where you are trying to record the video!
import MobileCoreServices
Then overall your code will something like this
var imag = UIImagePickerController()
imag.delegate = self
imag.sourceType = UIImagePickerControllerSourceType.Camera;
imag.cameraDevice = UIImagePickerControllerCameraDevice.Rear //or Front
imag.mediaTypes = [kUTTypeMovie];
self.presentViewController(imag, animated: true, completion: nil)
This method will opens the library of videos in my ipod 4.Not the video camera of my device.
Will someone tell me how to sort out from the problem ,I have tried the both ways described above.
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsEditing = YES;
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
imagePickerController.delegate = self;
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
and
imagePickerController.mediaTypes =
[NSArray arrayWithObject:(NSString *)kUTTypeMovie];
Thanks for your help.
enter code herePlease try this,this will opens the video camera
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *tmp_picker=[[UIImagePickerController alloc]init];
tmp_picker.sourceType=UIImagePickerControllerSourceTypeCamera;
tmp_picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
tmp_picker.delegate=self;
[self presentModalViewController:tmp_picker animated:YES];
[tmp_picker release];
NSLog(#"button index is %i",buttonIndex);
}