Gamecenter Matchmaking Doesn't Work - objective-c

Here is my Menu.m's onEnter method:
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = 2;
request.maxPlayers = 2;
GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
mmvc.matchmakerDelegate = self;
tempVC = [[UIViewController alloc] init];
[[[CCDirector sharedDirector] view] addSubview:tempVC.view];
[tempVC presentModalViewController: mmvc animated: NO];
mmvc.view.frame = CGRectMake(150, 150, 510, 420);
I tried with device and simulator but they couldn't match.
I also tried it to do by following Ray Wenderlich's tutorial:
But then, even matchmakerviewcontroller didn't show up. I don't know what I'm doing wrong.
Thanks in advance.

Are you using two different game center IDs -- one for your simulator and one for your device?
Is your device logged into the game center sandbox?
The simulator will use the game center sandbox, and your device must also use the sandbox for the two to connect.
You can log into the game center sandbox by logging out of the game center, and then starting your app. Your app should ask you to log into game center. Performing the login through your non-released app will put you in the game center sandbox.

Related

Objective C iOS WKWebView Background

Hopefully someone can help.
I've got an application that currently uses the UIWebview to play audio, which works even if the device is locked as I enable mediaPlaybackAllowsAirPlay.
However I started to move the code to use the new WKWebView and I've enabled mediaPlaybackAllowsAirPlay, However when I press the lock button, the WebView stops playing the audio.
Any ideas how I can get WKWebview to behave like the UIWebView?
Update, Here's an example of my code:
WKUserContentController *wkUController = [[WKUserContentController alloc] init];
WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
theConfiguration.userContentController = wkUController;
theConfiguration.allowsAirPlayForMediaPlayback = YES;
webViewActive = [[WKWebView alloc] initWithFrame:viewForWeb.frame configuration:theConfiguration];
webViewActive.navigationDelegate = self;
webViewActive.frame = viewForWeb.bounds;
[webViewActive setAutoresizingMask: UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
[viewForWeb addSubview:webViewActive];
NSURL *nsurl=[NSURL URLWithString:#"URL TO AUDIO"];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webViewActive loadRequest:nsrequest];
Thanks

how to switch camera mode to video mode using GPUImage in ios

I am making app like Instagram .i am using GPUImage framework ,in this i have to take photos and videos and share. i able to capture photos using this framework and now i have to capture video but i am struggling how to change camera mode photos to video. any help and tutorial then its very good for me. I used this code camera for photos mode.
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
self.imagepicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[[NSBundle mainBundle] loadNibNamed:#"OverlayView" owner:self options:nil];
self.overlayView.frame = self.imagepicker.cameraOverlayView.frame;
self.imagepicker.cameraOverlayView = self.overlayView;
self.overlayView = nil;
CGSize result = [[UIScreen mainScreen] bounds].size;
self.imagepicker.showsCameraControls = NO;
self.imagepicker.allowsEditing = NO;
self.imagepicker.wantsFullScreenLayout = NO;
// self.imagepicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
}
else{
self.imagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
In my case, I'm using GPUImage to do both (pictures and videos). Therefore I've created two objects: one of type GPUImageStillCamera(pictures) and other of type GPUImageVideoCamera (videos).
So whenever you need to switch between cameras you basically stop the GPUImageStillCamera capture and initialize a video camera (note that you have to adapt this snippet to your project):
func initializeVideoCamera() {
// Stop the capture of GPUImageStillCamera
stillCamera.stopCameraCapture()
videoCamera = GPUImageVideoCamera.init(sessionPreset: AVCaptureSessionPreset1920x1080, cameraPosition: .Back)
videoCamera?.outputImageOrientation = .Portrait
videoCamera?.addTarget(filter)
// If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie
unlink(pathToMovieFile)
initializeWriteWithPath(pathToMovieFile)
videoCamera?.startCameraCapture()
}

How to disable Preview screen when using UIImagePickerController Camera

In iOS7 the build-in camera app doesn't go into the preview screen after taking a picture, is there any way that the UIImagePicker can behave like that.
UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
I know another solution is to create a custom camera using the AVFoundation class, but that is beyond my knowledge at this point and I really like the looks of the default camera.
Update
So after some more research I found out I could create my own shutter button and set it as a camera overlay. Here is what I did
UIButton *shutter = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[shutter addTarget:self action:#selector(shootPicture) forControlEvents:UIControlEventTouchUpInside];
[shutter setTitle:#"S" forState:UIControlStateNormal];
shutter.frame = CGRectMake(50, 50, 60, 60);
UIView *layoutView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
layoutView.opaque = NO;
layoutView.backgroundColor = [UIColor clearColor];
[layoutView addSubview:shutter];
For the 'shootPicture' method
- (void) shootPicture
{
[picker takePicture];
[self imagePickerController:self.camCtl didFinishPickingMediaWithInfo:nil];
}
If I just have the picker call 'takePicture' I will still get the preview, so instead I forced the picker to call didFinishPickingMediaWithInfo right after taking picture. The result is I don't see the preview screen HOWEVER I don't see the picture either. I know I put 'nil' in didFinishPickingMediaWithInfo because I don't know what to put in at this point. I also know it took a picture is in cache somewhere but I really have no idea how to get it.
Any idea would be greatly appreciated =)
This solution works for me:
self.pickerController.allowsEditing = false

UIBarButtonItem textures offset when iPhone only app is run on iPad

In the main view of my app, I instantiate 3 UIBarButtonItem(2 actual buttons and 1 flexible spacer) with custom images (created using [UIImage imageNamed:]), then set them as the items of a UIToolBar. Here's the code:
-(void)viewDidLoad{
[super viewDidLoad];
UIToolbar *menuBar = [UIToolbar new];
menuBar.barStyle = UIBarStyleDefault;
CGRect viewBounds = [UIScreen mainScreen].bounds;
//menuBar is rotated to be viewed vertically along the right side of the device in portrait orientation, the app does not support device rotation
menuBar.transform = CGAffineTransformRotate(menuBar.transform, M_PI * 0.5f);
[menuBar setFrame:CGRectMake(viewBounds.size.width - menuBarHeight, 5, menuBarHeight, viewBounds.size.height)];
[self.view addSubview:menuBar];
[menuBar release];
UIBarButtonItem
*peekButton = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:#"peekIcon.png"]
style:UIBarButtonItemStyleDone
target:self
action:#selector(peek:)],
*pauseButton = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:#"pauseIcon.png"]
style:UIBarButtonItemStyleDone
target:self
action:#selector(pauseGame:)],
*flexSpace = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
menuBar.items = #[flexSpace, pauseButton, peekButton];
[flexSpace release];
[pauseButton release];
[peekButton release];
}
When run on a iPod touch running iOS 5.1, the toolBar and buttons appear as expected, like so:
but when run on an iPad(iOS 4.3), the textures look like this:
I can not seem to discern the cause, however, I believe it may be an OS, or device specific bug, as I keep encountering similarly obscure graphics issues where UI elements are drawn with total disregard for the underlaying object's data. Unfortunately I can't find any relevant docs (Apple or other wise) to shed some light on this issue.
Any input is greatly appreciated, thanks.
The issue seems to arise from calling UINavigationController's method
-(void)pushViewController:(UIViewController*)viewController animated:(BOOL)animated;
As screen transitions were not originally intended to be animated, the animated argument was NO. Changing the value to YES seems to be the solution.
This also seems to have solved some other graphics issues I was experiencing.

applicationMusicPlayer volume notification

I am using an applicationMusicPlayer and when i try to change the volume appear the visual notification, as shown in the picture.
Here the code I am using:
[MPMusicPlayerController applicationMusicPlayer] setVolume:newVolune];
Anyone knows how to hide this notification?
I don't know where the docs says so, but if you add a MPVolumeView view to your app the system volume overlay goes away. Even if it is not visible:
- (void) viewDidLoad
{
[super viewDidLoad];
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame: CGRectZero];
[self.view addSubview: volumeView];
[volumeView release];
...
}
You can use the hardware volume buttons, the setVolume method or directly interact with the control (if visible) that the overlay doesn't show up.
For iOS6 I had to set an image with alpha 0 and non-zero size to the MPVolumeView's image fields in order to get the default volume change notification to disappear.
// hide the hardware volume slider
UIImage *thumb = [[UIImage alloc] initWithCIImage:[UIImage imageNamed:#"volumeHider"].CIImage scale:0.0 orientation:UIImageOrientationUp];
MPVolumeView *hwVolume = [[MPVolumeView alloc] initWithFrame:self.frame];
[hwVolume setUserInteractionEnabled:NO];
hwVolume.showsRouteButton = NO;
[hwVolume setVolumeThumbImage:thumb forState:UIControlStateNormal];
[hwVolume setMinimumVolumeSliderImage:thumb forState:UIControlStateNormal];
[hwVolume setMaximumVolumeSliderImage:thumb forState:UIControlStateNormal];
[self addSubview:hwVolume];
This made the MPVolumeView be "visible" on the screen, but invisible to the user.
I encountered the same issue recently. Instead of adding the MPVolumeView to current view controller's view, I add it to the application's window once at the start of the app:
CGRect rect = CGRectMake(-500, -500, 0, 0);
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:rect];
[self.window addSubview:volumeView];
This works in both iOS 7 and 8.
Swift 3
You can hide the System MPVolumeView using
override func viewDidLoad() {
super.viewDidLoad()
let volumeView = MPVolumeView(frame: CGRect.zero)
self.view.addSubview(volumeView)
}
I had success with this in iOS 6. Although it wouldn't perform well. It caused quite a bit of lag when sliding the thumbImage. I did have to take out the last 2 lines of code in order for this to work.
[volumeView release];
...
For me, on iOS 7, none of above solutions worked. Here is how I did it:
_volume = [[MPVolumeView alloc] initWithFrame: CGRectMake(-100,-100,16,16)];
_volume.showsRouteButton = NO;
_volume.userInteractionEnabled = NO;
[self.view addSubview:_volume];
[_volume release];
That is, simply set MPVolumeView's frame to an off-screen location such as (-100,-100).