iOs: Error while cancelling performrequest - ios

In my iOs SpriteKit application, I play voice overs using the AVAudioPlayer after a certain amount of seconds after a user action, like so:
[self.vOSoundManager performSelector:#selector(playVoiceOverWithName:) withObject:#"Voiceover_waarhondenbrokken3" afterDelay:8.0];
[self.vOSoundManager setRequestBeingPerformed:TRUE];
When a user performs another action, the sound should stop playing. I do this like so:
if(self.vOSoundManager.requestBeingPerformed){
[NSObject cancelPreviousPerformRequestsWithTarget:self.vOSoundManager];
[self.vOSoundManager stopCurrentSound];
}
The stopCurrentSound method in VoiceOverSoundManager:
- (void)stopCurrentSound{
self.playing = FALSE;
[self.voiceOverPlayer stop];
self.voiceOverPlayer = nil;
}
When the cancelPreviousPerformRequestsWithTarget method is called, I get the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[VoiceOverSoundManager name]: unrecognized selector sent to instance 0x155a9590'
I have no idea why. Does anyone have a solution?

If you are using one instance of player to play all sounds in your game, this could be a problem if you don't re-create it after stopCurrentSound method is executed:
self.voiceOverPlayer = nil;
Try to remove this line or create a new player instance.

Related

URL background session downloadTask error

I want to know whether completion handler blocks are supported in background sessions.
Right now, I'm getting this error:
libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
There are two ways for a session to download:
use delegate methods
use completion handlers like below.
However, when I'm using the following code I'm getting the error.
let session_config = URLSessionConfiguration.background(withIdentifier: "myID");
let session = URLSession(configuration: session_config);
let task=session.downloadTask(with: request) { (url,response,error) in
}
task.resume()

Customize camera overlay in applozic

I am using applozic chat sdk for ios and sending images , video successfully . My requirement is to change camera overlay. When I try to add overlay on camera it crashes.
let camaraObj : ALImagePickerController = ALImagePickerController()
let overlay =UIView(frame: UIScreen.mainScreen().bounds)
overlay.backgroundColor = UIColor.redColor()
camaraObj.cameraOverlayView = overlay
Crash log: libc++abi.dylib: terminating with uncaught exception of type NSException.
Any help ?
Looks like you are not setting the sourceType. ALImagePickerController is used for sending pictures from photos only. You need to explicitly set source type if you want to use it for camera.
i.e. self.mImagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
We just tried the same and got below exception:
2017-01-30 14:30:30.954540 applozicdemo[3106:1925853] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Source type must be UIImagePickerControllerSourceTypeCamera' First throw call stack:
(0x1819de1c0 0x18041855c 0x187a945cc 0x187d23294 0x1003f9dcc 0x10016525c 0x10016521c 0x10016a284 0x18198bf2c 0x181989b18 0x1818b8048 0x18333e198 0x1878a42fc 0x18789f034 0x1000517b8 0x18089c5b8)
libc++abi.dylib: terminating with uncaught exception of type NSException

App crashes when trying to resign keyboard

Since I updated to the latest Xcode 6 beta, I have been having issues with closing the keyboard. My app is crashing each time I try to close the keyboard, even though I have used the same code for ages and it used to work fine.
Here is what I have:
#IBAction func viewTapped(sender : AnyObject) {
//Closes keyboard when user touches screen.
transactionDateInput.resignFirstResponder()
transactionNameInput.resignFirstResponder()
textField.resignFirstResponder()
notesField.resignFirstResponder()
UIView.animateWithDuration(1.5, animations: {
self.valueEnter.alpha = 0
self.dateEnter.alpha = 0
self.notesDone.alpha = 0
})
}
Someone suggested changing it to something like this:
if (transactionDateInput.isFirstResponder() == true){
transactionDateInput.resignFirstResponder()
}
but that makes no difference. Anyone have any suggestions? Here is the error:
AffordIt[4445:1334424] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AffordIt.SecondViewController textFieldShouldReturn:]: unrecognized selector sent to instance 0x7fb169666880'
Check your Text Field outlet delegate (right click to Text Field)
there should be delegate to your UIViewController!
Look at this tutorial

Catching NSException in main

The iOS application i took over has a way of handling NSExceptions differently than what i've seen before and wanted to know why it isn't working now.
In the main.m file the old developer has this logic in it:
int main(int argc, char *argv[])
{
#autoreleasepool {
int retVal = 0;
#try {
retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
#catch (NSException *exception) {
//
//Logic to save Exception in DataStore
//
NSLog(#"Exception - %#",[exception description]);
exit(EXIT_FAILURE);
}
return retVal;
}
}
When the app would get launched again you would receive a prompt to send the exception to us and if you confirmed it would sent it to our server.
I recently pushed an update more optimized for iOS 7 of the application and noticed that i don't get any of these error reports from crashed apps anymore.
So i tested it via the following code which i know gets called:
NSArray *array = [NSArray new];
id object = [array objectAtIndex:4];
To which i receive this:
2014-05-12 14:55:57.575 APPNAME[17989:60b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 4 beyond bounds for empty array'
*** First throw call stack:
(0x18ab0b09c 0x196a89d78 0x18aa0c680 0x10007f498 0x18d9e02c0 0x18da997d0 0x18da996cc 0x18da98ba0
0x18da98840 0x18da98564 0x18da984e4 0x18d9dad78 0x18d5d70cc 0x18d5d1c94 0x18d5d1b4c
0x18d5d13d4 0x18d5d1178 0x18d5caa30 0x18aacb7e0 0x18aac8a68 0x18aac8df4 0x18aa09b38
0x19042f830 0x18da480e8 0x100036b98 0x197073aa0)
libc++abi.dylib: terminating with uncaught exception of type NSException
As you can see the exception is not being logged or saved but rather it is completely uncaught.
2 Questions:
Is this bad practice? I don't think it is but i am a jr. developer and not really sure and if there is a better way to do this w/o third party service?
Do you know of any changes in iOS 7 that would affect this (UNTOUCHED) Logic?
Is this bad practice? I don't think it is but i am a jr. developer and
not really sure and if there is a better way to do this w/o third
party service?
Yes, it is bad practice. UIApplicationMain() is a black hole; once control is passed to that function, it is unlikely that any code beyond that call in main() will ever be invoked again.
It is also a naive implementation; it logs less information to stdout than the normal exception handling mechanism (which is the output you are seeing). It hides information that would be useful to debugging and would also, likely, bypass the standard crash reporting mechanism.
Note that there is also a global unhandled exception handling hook. I wouldn't recommend using it, but it does exist.
Do you know of any changes in iOS 7 that would affect this (UNTOUCHED)
Logic?
Not off hand, but I haven't looked. Again, though, UIApplicationMain() is a black hole; it doesn't typically return ever.
According to Exception Programming Topics you can use NSSetUncaughtExceptionHandler function to handle uncaught exceptions. Try the code below:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSSetUncaughtExceptionHandler(handleUncaughtException);
#throw [NSException exceptionWithName:NSGenericException
reason:#"Test uncaught exception handling"
userInfo:nil];
return YES;
}
void handleUncaughtException(NSException *exception)
{
NSLog(#"Exception - %#",[exception description]);
exit(EXIT_FAILURE);
}

UITextFieldView markedTextRange crash on iOS4?

My apps use UITextFieldView to receive input method from user and work fine on iOS6/iOS7. and I am using the following code to prevent user input chinese/japanese/something like that. Method to detect the real input words:
-(void)textFieldChanged:(UITextField *)textField
//crash here if device iOS version at 4.3
UITextRange *selectRange = [textField markedTextRange];
if (selectRange == nil)
//get word to do something...
Crash log :
2013-11-20 12:35:09.480 [My app][203:607]-[UITextField markedTextRange]: unrecognized selector sent to instance 0x287e270
2013-11-20 12:35:09.480 [My app][203:607] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITextField markedTextRange]: unrecognized selector sent to instance 0x287e270'

Resources