I'm using UIImagePickerController to take pictures and videos from my app. Toggling between the two isn't too bad. If the user chooses to record a video, I first check this:
if (picker.cameraCaptureMode == UIImagePickerControllerCameraCaptureModeVideo)
{
[self captureVideo];
}
else
{
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
[self captureVideo];
}
This usually works totally fine. Here's the catch. I'm also using OpenTok by Tokbox to do video calls, and it seems like the captureMode assignment doesn't work after a video call. It seems completely crazy, but I made this modification to do some debugging:
if (picker.cameraCaptureMode == UIImagePickerControllerCameraCaptureModeVideo)
{
[self captureVideo];
}
else
{
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
if (picker.cameraCaptureMode != UIImagePickerControllerCameraCaptureModeVideo)
{
NSLog(#"Assignment unsuccessful???")
}
[self captureVideo];
}
And i get this "Assignment unsuccessful???" log every single time. UIImagePickerController must not be allowing the assignment or something. I really can't figure it out. I've also made a forum post on OpenTok's site to see if they're possibly not releasing some camera resources, but I don't think it's their problem.
Any insight here?
Use:
+ (NSArray *)availableCaptureModesForCameraDevice:(UIImagePickerControllerCameraDevice)cameraDevice
to check which source types are available. Also if you're using a simulator, it will never assign properly.
Solved with a solution on the TokBox forum. I needed to first change my audio session before trying to access the microphone.
AVAudioSession *mySession = [AVAudioSession sharedInstance];
[mySession setCategory:AVAudioSessionCategorySoloAmbient error:nil];
[self presentViewController:picker animated:YES completion:NULL];
Related
I'm using TWTRComposerViewController to share video on twitter my landscape app, it is working fine in all other device's except iPhone-X , when i try to share video in iPhone-X then composer not showing and the App freezes out.
I'm using the below written code:
if ([[Twitter sharedInstance].sessionStore hasLoggedInUsers])
{
dispatch_async(dispatch_get_main_queue(), ^{
TWTRComposerViewController *composer = [[TWTRComposerViewController emptyComposer] initWithInitialText:#"Testing" image:nil videoURL:url];
composer.delegate = self;
[self presentViewController:composer animated:true completion:nil];
});
}
else
{
[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
if (session) {
dispatch_async(dispatch_get_main_queue(), ^{
TWTRComposerViewController *composer = [[TWTRComposerViewController emptyComposer] initWithInitialText:#"Testing" image:nil videoURL:url];
composer.delegate = self;
[self presentViewController:composer animated:true completion:nil];
});
} else {
NSLog(#"Error");
}
}
The glitch you are encountering with the TWTRComposerViewController is not your error, nor are you the only one dealing with this.
This is a bug in Twitter's SDK.
Looking into Twitter's recent activity / attention to their SDK it seems their interface packages are lagging ever since the new iPhone X release. I would expect this to be resolved sooner than later.
I guess the best temporary solutions would be to either force your controller into portrait mode during this process, disable rotation for the appropriate controllers, or (though perhaps too ugly) present this VC in portrait, and rotate the view. Nonetheless, hopefully Twitter updates their SDK soon.
Report this as a bug to Twitter on their developer forum to let them know about the issue, as they should eventually see the numerous posts of the same issue...
I have an application which requires to use the microphone for recording user voice. I'm trying to make a speech to text.
I'm work with SpeechKit.framework and below is my code used:
-(void)starRecording{
self.voiceSearch = [[SKRecognizer alloc] initWithType:SKSearchRecognizerType
detection:SKShortEndOfSpeechDetection
language:[[USER_DEFAULT valueForKey:LANGUAGE_SPEECH_DIC] valueForKey:#"record"]
delegate:self];
}
- (void)recognizer:(SKRecognizer *)recognizer didFinishWithResults:(SKRecognition *)results {
long numOfResults = [results.results count];
if (numOfResults > 0) {
// update the text of text field with best result from SpeechKit
self.recordString = [results firstResult];
[self sendChatWithMediaType:#"messageCall" MediaUrl:#"" ContactDetail:#"{}" LocationDetail:#"{}"];
[self.voiceSearch stopRecording];
}
if (self.voiceSearch) {
[self.voiceSearch cancel];
}
[self starRecording];
}
That makes the SKRecognizer to be always open and that thing reduce the application performance.
I want to start the SKRecognizer when the microphone is detecting input audio.
I have a method for that? A method which is called when the microphone have input sound for me or a method which is always returning the level of audio detected?
Thank you!
You need to use the SpeechKit class to set up the audio.
Look here for details;
http://www.raywenderlich.com/60870/building-ios-app-like-siri
This project shows how to detect audio threshold;
github.com/picciano/iOS-Audio-Recoginzer
I am making a multiplayer game for iOS and I read the material in Apple Developer Center, specifically this one. Here is my code for custom matchmaking, which is pretty straightforward:
- (void)findProgrammaticMatch {
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 2;
request.defaultNumberOfPlayers = 2;
request.playersToInvite = nil;
request.playerAttributes = 0;
request.playerGroup = 0;
UILabel *loading = (UILabel *)[aiw viewWithTag:792];
[[GKMatchmaker sharedMatchmaker] findMatchForRequest:request withCompletionHandler:^(GKMatch *match, NSError *error) {
if (error){
//error handling
[loaderLayer stopAnimating];
UIButton *cancelButton = (UIButton *)[loaderLayer viewWithTag:442];
[cancelButton setTitle:#"Go Back" forState:UIControlStateNormal];
loading.text = #"Cannot find any players. Please try again later.";
} else if (match != nil) {
//save match
self.match = match;
self.match.delegate = self;
loading.text = #"Found a player. Preparing session...";
if (!self.matchStarted && match.expectedPlayerCount == 0) {
self.matchStarted = YES;
//begin game logic
[self.scene setState:1];
self.myTicket = 1000+arc4random_uniform(999);
[self.scene send:self.myTicket];
[self stopLoading];
}
}
}];
}
However, matchmaking fails when one or more devices are connected to the internet via cellular networks. When I investigated the underlying error I found out that even if it is a wifi to wifi case, the completion handler does not work as intended. That is, match.expectedPlayerCount is never 0. Instead, the game starts when - (void)match:(GKMatch *)match player:(NSString *)playerID didChangeState:(GKPlayerConnectionState)state handler is invoked after the completion handler as following:
...
- (void)match:(GKMatch *)match player:(NSString *)playerID didChangeState:(GKPlayerConnectionState)state {
switch (state) {
case GKPlayerStateConnected:
self.matchStarted = YES;
//begin game logic
[self.scene setState:1];
self.myTicket = 1000+arc4random_uniform(999);
[self.scene send:self.myTicket];
[self stopLoading];
break;
...
The problem now is if a device with 3g is connected (and matched-sort of) didChangeState is never invoked. I checked for several other related questions on the internet and this site, although they are far from being satisfactory. I also read that sandbox servers of Game Center are not reliable and for some people production version worked perfectly(it just works!) despite the errors in sandbox mode, but I don't want to take that risk. Has anybody have experienced similar problem with their multiplayer game?
Hgeg,
There is nothing wrong with your code.
You have to allow cellular data usage to your app which needs users permission.
The following paragraph is selected from Apple's support website :
At the Foundation layer, you can use the setAllowsCellularAccess:
method on NSMutableURLRequest to specify whether a request can be sent
over a cellular connection. You can also use the allowsCellularAccess
to check the current value.
At the Core Foundation layer, you can achieve the same thing by
setting the kCFStreamPropertyNoCellular property before opening a
stream obtained from the CFSocketStream or CFHTTPStream APIs.
In older versions of iOS, you can continue to use the
kSCNetworkReachabilityFlagsIsWWAN as a best-effort way of determining
whether traffic will be sent over a cellular connection, but you
should be aware of its limitations.
Good luck
Iman
According to the latest apple news, from iOS 9, the sand box mode will no longer exist, instead of the sandbox you'll have one unified environment.
So you'll have just one unified environments where you can share the same accounts, this should solve all the usual problems from the SandBox mode.
The new Unified System it's also compatible with TestFlight so you'll be able to test you code across multiple device and accounts.
All of these changes will be made directly by apple, so the only think that you can do it's to wait until they update to the new system, so far it's the only way to be sure that it's not a Sand Box problem.
For more info please have a loot at the WWDC video
Based on the code that you have shown us, there should'nt be any issue regardless of the connection type, 3G or otherwise; however, if you previously interspersed code for exception handling that was tied back to connection status, or for graphics which represent a loading state, something could be tied up elsewhere logically and produce this error at this point in the game logic. Even a corrupt spinner graphic can become an issue.
Did you have any other exception handlers in the code that called the following:
request.playersToInvite
or
request.playerGroup
or
that changed a loader layer characteristic?
I'm facing the black screen preview in UIIMagePickercontroller. I tried many solutions but cannot solved that. Any body can help me to solve that? It's always happens when I open the photo library and select some photos, then add new cellItem in UICollectionview, after that I open camera to take new photo and the issue is happened.
Here is my code used to open Camera:
-(void)actionLaunchAppCamera
{
dispatch_async(dispatch_get_main_queue(), ^{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
if (self.cameraPickerController == nil) {
self.cameraPickerController= [[UIImagePickerController alloc] init];
self.cameraPickerController.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
self.cameraPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
self.cameraPickerController.showsCameraControls = YES;
self.cameraPickerController.allowsEditing = YES;
}
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
// self.cameraPickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto||UIImagePickerControllerCameraCaptureModeVideo;
self.cameraPickerController.delegate = self;
self.cameraPickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.cameraPickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
self.cameraPickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
self.cameraPickerController.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:self.cameraPickerController
animated:YES completion:^
{
// BE SURE TO USE a completion block!!!
// completion stuff in here
}];
}
}
});
}
Thanks in advance.
I tried everything without luck until I set my Bundle Display Name to "whatever", in the Info.plist.
After this, the app asked for permissions as expected and the camera works.
I only wasted a day on this, which seems well below the median on StackOverflow. Hope it rescues others from this torturous bug.
The problem is not your code. It's apple's API. You can make see the same problem in Apple contact, if you edit the picture, save it and then go back and edit it agin. Then you will have a black preview. Take a picture any way and repeat the process, then it will be fine. It also does it in text message picture. Reset the device to factory settings and everything will work for a while. I have reported to Apple 3 months ago and still nothing from them. One would think if Apple had a bug report in their core apps they would fix it. This problem has really been a pain and yet IOS 6 had no problems.
At the moment I'm working on a iPhone app and I have a problem.
I want, that the player can send a gamecenter friendrequest.
In the apple Guide there are two methods I'm interested in.
The first would be
- (void)addRecipientsWithPlayerIDs:(NSArray *)playerids
and the second would be
- (void)setMessage:(NSString *)message
Now I don't know to put them in the right order to get on.
How can I set the player ID's and the message, and after that, how can I send the request.
Suppose you have player ids in friendsArray. Then try this:
GKFriendRequestComposeViewController *friendRequestViewController = [[GKFriendRequestComposeViewController alloc] init];
friendRequestViewController.composeViewDelegate = self;
[friendRequestViewController setMessage:#"Add your message here"];
if (friendsArray)
{
[friendRequestViewController addRecipientsWithPlayerIDs: friendsArray];
}
[self presentModalViewController: friendRequestViewController animated: YES];
Hope this helps.. :)