MPMoviePlayerController playing airPlay in background, crash when double tap home button - iphone

MPMoviePlayerController successfully plays airPlay when I go to the homescreen and app is in the background. But when i double tap the home button, the app crashes. This happens on iOS 5, but not is not on 4.3.
To exclude other code, I've created a new empty project that only executes the code bellow on button press.
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"]];
NSError *setCategoryError = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryError];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController setMovieSourceType:MPMovieSourceTypeStreaming];
[self addObservers];
[self.delegate addSubview:moviePlayerController.view];
if([moviePlayerController respondsToSelector:#selector(setAllowsAirPlay:)])
{
[moviePlayerController setAllowsAirPlay:YES];
}
moviePlayerController.fullscreen = YES;
moviePlayerController.scalingMode = MPMovieScalingModeAspectFit;
[moviePlayerController prepareToPlay];
[moviePlayerController play];
In the console i get the following output on crash:
Jan 27 12:08:01 unknown mediaserverd[295] <Error>: <<<< FIGSERVER >>>> FigPlayerRemoteServer_KillAndForceCrashReport: RPCTimeout message received to terminate [295] with reason 'fig rpc timeout -- FigSharedRemote_VolumeCategoryForAudioCategory'
Jan 27 12:08:01 unknown ReportCrash[308] <Notice>: MS:Notice: Installing: (null) [ReportCrash] (675.00)
Jan 27 12:08:01 unknown ReportCrash[308] <Error>: Saved crashreport to /Library/Logs/CrashReporter/mediaserverd-2012-01-27-120801.plist using uid: 0 gid: 0, synthetic_euid: 0 egid: 0
Jan 27 12:08:01 unknown mediaserverd[295] <Error>: <<<< FIGSERVER >>>> FigPlayerRemoteServer_KillAndForceCrashReport: RPCTimeout message received; stackshot generated
Jan 27 12:08:01 unknown mediaserverd[295] <Error>: <<<< FIGSERVER >>>> FigPlayerRemoteServer_KillAndForceCrashReport: TERMINATING our process [295]
Jan 27 12:08:02 unknown com.apple.launchd[1] <Notice>: (com.apple.mediaserverd) Exited: Killed: 9
Jan 27 12:08:02 unknown mediaserverd[310] <Notice>: MS:Notice: Installing: com.apple.mediaserverd [mediaserverd] (675.00)
Jan 27 12:08:02 unknown kernel[0] <Debug>: Sandbox: ignoring builtin profile for platform app: /usr/sbin/mediaserverd
Jan 27 12:08:02 unknown kernel[0] <Debug>: Sandbox: ignoring builtin profile for platform app: /usr/sbin/mediaserverd
Jan 27 12:08:03 unknown mediaserverd[310] <Error>: 12:08:03.383370 com.apple.AVConference: /SourceCache/GameKitServices/GameKitServices-344.3/AVConference.subproj/Sources/AVConferenceServer.m:1862: AVConferenceServerStart aborting - device doesn't support conferencing
and in the crashreport:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x33bab8bf 0x33af2000 + 759999
1 libobjc.A.dylib 0x31bcd1e5 0x31bc4000 + 37349
2 AVFoundation 0x374f6cb5 -[AVPlayerItem _attachToPlayer:forImmediateEnqueueing:shouldAppendItem:] + 341
3 AVFoundation 0x374e71f7 -[AVPlayer _insertPlaybackItemOfItem:inPlayerQueueAfterPlaybackItemOfItem:] + 43
4 AVFoundation 0x374eebf3 __-[AVPlayer _attachItem:andPerformOperation:withObject:]_block_invoke_2 + 1099
5 libdispatch.dylib 0x3641cd55 0x3641c000 + 3413
6 libdispatch.dylib 0x36427e8d 0x3641c000 + 48781
7 CoreFoundation 0x33b7e2dd 0x33af2000 + 574173
8 CoreFoundation 0x33b014dd 0x33af2000 + 62685
9 CoreFoundation 0x33b013a5 0x33af2000 + 62373
10 GraphicsServices 0x31f56fcd 0x31f53000 + 16333
11 UIKit 0x36d57743 0x36d26000 + 202563
12 AirplayTest 0x00002e45 main (main.m:16)
13 AirplayTest 0x00002dd4 start + 40
Any clues what could be wrong?

Have you tried setting the useApplicationAudioSession property of your movie player controller to NO (i.e. to simulate iOS 3.1 default behaviour) for iOS 5 only? There seem to be some bugs around the audio session handling in iOS 5 that can cause the audio server to die when you switch between apps, handle interruptions etc.
If this fixes it, please submit a bug report to Apple, as it's more of a hack than a fix!

This seems to be a bug within iOS release 5.0. With the release of iOS 5.1 it seems to have been fixed.
Thanks to #Cyril for confirmation on this.

Related

App crash in didFinishPickingMediaWithInfo

My app is crashing when the user records a video and then clicks choose. Here is my code:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
//picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];
picker.allowsEditing = NO;
picker.delegate = self;
picker.videoQuality = UIImagePickerControllerQualityTypeMedium;
[self presentModalViewController:picker animated:YES];
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// [self dismissModalViewControllerAnimated:YES];
AppDelegate *del = [[UIApplication sharedApplication]delegate];
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
moviePath = [[info objectForKey:UIImagePickerControllerMediaURL]path];..//using this for upload
del.globalMoviePath = moviePath;
if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0)== kCFCompareEqualTo)
{
moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
del.globalMoviePath = moviePath;
picker.videoMaximumDuration = 60.0f;
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
NSLog(#"nrgkrg===>%#",moviePath);
videoUrl=(NSURL*)[info objectForKey:UIImagePickerControllerMediaURL];
NSLog(#"Urlllll===>%#",videoUrl);
videoData = [NSData dataWithContentsOfURL:videoUrl];
del.globalMoviePath = moviePath;
NSLog(#"video is====>%#",del.globalMoviePath);
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoUrl];
UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
[player stop];
videoImage = [[UIImageView alloc]initWithImage:thumbnail];
//NSLog(#"imegsvideo====>%#",thumbnail);
//if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath))
//{
// UISaveVideoAtPathToSavedPhotosAlbum (moviePath, self, #selector(video:didFinishSavingWithError:contextInfo:), nil);
// }
//MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoUrl];
//UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
}
[self dismissModalViewControllerAnimated:YES];
//[[picker parentViewController] dismissModalViewControllerAnimated: YES];
}
When the user records a video and clicks choose app gets crashed but works fine when selected from camera roll.
Please help!!
Here's the log:
Nov 29 20:28:14 ReportCrash[259] <Notice>: Formulating crash report for process [254]
Nov 29 20:28:14 com.apple.launchd[1] <Warning>: (UIKitApplication:[0xcc37]) Job appears to have crashed: Segmentation fault: 11
Nov 29 20:28:14 backboardd[52] <Warning>: Application 'UIKitApplication:[0xcc37]' exited abnormally with signal 11: Segmentation fault: 11
Nov 29 20:28:14 ReportCrash[259] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
Nov 29 20:28:14 ReportCrash[259] <Notice>: Saved crashreport to /var/mobile/Library/Logs/CrashReporter/ using uid: 0 gid: 0, synthetic_euid: 501 egid: 0
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) mstreamd: Checking on job state for Photo Stream
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) mstreamd: No jobs scheduled for Photo Stream.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) mstreamd: Checking on job state for Shared Stream
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) mstreamd: No jobs scheduled for Shared Stream.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) PS: Media stream daemon stopping.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) AS: <MSIOSAlbumSharingDaemon: 0x1ee72590>: Shared Streams daemon shutting down.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) AS: <MSIOSAlbumSharingDaemon: 0x1ee72590>: Shutting down state machine for personID 1446684163.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) AS: <MSASStateMachine: 0x1ed3e060>: Shutting down uploader.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) AS: <MSASStateMachine: 0x1ed3e060>: Shutting down downloader.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) AS: <MSASStateMachine: 0x1ed3e060>: Shutting down state machine.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) AS: <MSIOSAlbumSharingDaemon: 0x1ee72590>: Shutting down model.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) AS: <MSASServerSideModel: 0x1ed39d50>: Command Queue has shut down.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) AS: <MSIOSAlbumSharingDaemon: 0x1ee72590>: Model has shut down.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) AS: <MSIOSAlbumSharingDaemon: 0x1ee72590>: Shared Streams daemon has shut down.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) mstreamd: <MSPowerBudget: 0x1ed394b0>: Stopping post-foreground timer.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Warn ) mstreamd: mstreamd shutting down.
Nov 29 20:49:16 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state pluggedin_screen_off even though we are not in it, doing nothing
Nov 29 20:49:16 kernel[0] <Debug>: AppleD1881PMUPowerSource: AppleUSBCableDetect 0
Nov 29 20:49:16 kernel[0] <Debug>: AppleD1881PMUPowerSource: AppleUSBCableType Detached
Nov 29 20:49:16 kernel[0] <Debug>: virtual IOReturn AppleUSBDeviceMux::message(UInt32, IOService *, void *) - kMessageInterfaceWasDeActivated
Nov 29 20:49:16 kernel[0] <Debug>: AppleUSBDeviceMux::reportStats: USB mux statistics:
Nov 29 20:49:16 kernel[0] <Debug>: USB mux: 190 reads / 0 errors, 899 writes / 0 errors
Nov 29 20:49:16 kernel[0] <Debug>: USB mux: 0 short packets, 0 dups
Nov 29 20:49:16 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state pluggedin_charging even though we are not in it, doing nothing
Nov 29 20:49:16 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state unplugged_screen_off even though we are not in it, doing nothing
Nov 29 20:49:16 ptpd[104] <Notice>: PTP interface has been deactivated.
Nov 29 20:49:18 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state unplugged_asleep even though we are not in it, doing nothing
Nov 29 20:49:18 kernel[0] <Debug>: AppleD1881PMUPowerSource: AppleUSBCableDetect 1
Nov 29 20:49:18 kernel[0] <Debug>: AppleD1881PMUPowerSource: AppleUSBCableType USBHost
Nov 29 20:49:18 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state unplugged_screen_off even though we are not in it, doing nothing
Nov 29 20:49:18 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state pluggedin_screen_off even though we are not in it, doing nothing
Nov 29 20:49:19 ptpd[104] <Notice>: PTP interface has been activated at high speed.
Nov 29 20:49:56 lockdownd[29] <Notice>: 2fe93000 special_case_get: MGCopyAnswer(kMGQMobileEquipmentIdentifier) returned NULL
Nov 29 20:49:56 lockdownd[29] <Notice>: 2fe93000 copy_phonenumber: CTSettingCopyMyPhoneNumber() returned NULL
Nov 29 20:49:56 mobile_installation_proxy[265] <Error>: 0x3cbd7b88 MobileInstallationSlowLookupBreak: MobileInstallationBrowse was called without specifying an options dictionary containing kLookupReturnAttributesKey. This usage is inefficient and may cause performance problems. Break on MobileInstallationSlowLookupBreak to debug.
Nov 29 20:49:56 mobile_installation_proxy[265] <Error>: 0x3cbd7b88 MobileInstallationSlowLookupBreak: Existing options dictionary: <CFBasicHash 0x1c545b90 [0x3bfb1100]>{type = mutable dict, count = 1,
entries =>
6 : <CFString 0x1c545bc0 [0x3bfb1100]>{contents = "ApplicationType"} = <CFString 0x1c545b30 [0x3bfb1100]>{contents = "User"}
}
Nov 29 20:49:57 mc_mobile_tunnel[267] <Notice>: (Note ) MC: mc_mobile_tunnel starting.
Nov 29 20:49:57 mc_mobile_tunnel[267] <Notice>: (Note ) MC: mc_mobile_tunnel shutting down.
Nov 29 20:49:57 mc_mobile_tunnel[268] <Notice>: (Note ) MC: mc_mobile_tunnel starting.
Nov 29 20:49:57 mc_mobile_tunnel[268] <Notice>: (Note ) MC: mc_mobile_tunnel shutting down.
Nov 29 20:49:57 lockdownd[29] <Notice>: 2fe93000 set_response_error: handle_start_session SessionActive
Nov 29 20:49:57 lockdownd[29] <Notice>: 2fe93000 set_response_error: handle_start_session SessionActive
Nov 29 20:50:03 mc_mobile_tunnel[270] <Notice>: (Note ) MC: mc_mobile_tunnel starting.
Nov 29 20:50:03 mc_mobile_tunnel[270] <Notice>: (Note ) MC: mc_mobile_tunnel shutting down.
Nov 29 20:51:31 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state pluggedin_screen_off even though we are not in it, doing nothing
Nov 29 20:51:31 kernel[0] <Debug>: AppleD1881PMUPowerSource: AppleUSBCableDetect 0
Nov 29 20:51:31 kernel[0] <Debug>: AppleD1881PMUPowerSource: AppleUSBCableType Detached
Nov 29 20:51:31 kernel[0] <Debug>: virtual IOReturn AppleUSBDeviceMux::message(UInt32, IOService *, void *) - kMessageInterfaceWasDeActivated
Nov 29 20:51:31 kernel[0] <Debug>: AppleUSBDeviceMux::reportStats: USB mux statistics:
Nov 29 20:51:31 kernel[0] <Debug>: USB mux: 195 reads / 0 errors, 493 writes / 0 errors
Nov 29 20:51:31 kernel[0] <Debug>: USB mux: 0 short packets, 0 dups
Nov 29 20:51:31 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state pluggedin_charging even though we are not in it, doing nothing
Nov 29 20:51:31 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state unplugged_screen_off even though we are not in it, doing nothing
Nov 29 20:51:31 ptpd[104] <Notice>: PTP interface has been deactivated.
Nov 29 20:51:41 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state unplugged_asleep even though we are not in it, doing nothing
Nov 29 20:51:41 kernel[0] <Debug>: AppleD1881PMUPowerSource: AppleUSBCableDetect 1
Nov 29 20:51:41 kernel[0] <Debug>: AppleD1881PMUPowerSource: AppleUSBCableType USBHost
Nov 29 20:51:41 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state unplugged_screen_off even though we are not in it, doing nothing
Nov 29 20:51:41 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state pluggedin_screen_off even though we are not in it, doing nothing
Nov 29 20:51:41 ptpd[272] <Error>: ptpd: startResponder
Nov 29 20:51:41 kernel[0] <Debug>: launchd[272] Builtin profile: ptpd (sandbox)
Nov 29 20:51:42 ptpd[272] <Notice>: PTP interface has been activated at high speed.
Nov 29 20:51:43 lockdownd[29] <Notice>: 2ffcf000 verify_pair_record: The strings don't match. Is this really a UUID?
Nov 29 20:51:43 lockdownd[29] <Notice>: 2ffcf000 store_escrow_record: Creating escrow bag (hash=9263ecf9c114f3a5cecdf7a52df193b4ce25044f) for 30264900-17792825678462560
Nov 29 20:51:52 lockdownd[29] <Notice>: 01442000 verify_pair_record: The strings don't match. Is this really a UUID?
Nov 29 20:51:52 lockdownd[29] <Notice>: 01442000 store_escrow_record: Creating escrow bag (hash=9de39584e1758f58137d28e4bd8c2fd79b5ba0a2) for 30264900-1682617038156454252
Nov 29 20:51:53 lockdownd[29] <Notice>: 01442000 special_case_get: MGCopyAnswer(kMGQMobileEquipmentIdentifier) returned NULL
Nov 29 20:51:53 lockdownd[29] <Notice>: 01442000 copy_phonenumber: CTSettingCopyMyPhoneNumber() returned NULL
Nov 29 20:51:53 mobile_installation_proxy[275] <Error>: 0x3cbd7b88 MobileInstallationSlowLookupBreak: MobileInstallationBrowse was called without specifying an options dictionary containing kLookupReturnAttributesKey. This usage is inefficient and may cause performance problems. Break on MobileInstallationSlowLookupBreak to debug.
Nov 29 20:51:53 mobile_installation_proxy[275] <Error>: 0x3cbd7b88 MobileInstallationSlowLookupBreak: Existing options dictionary: <CFBasicHash 0x1c5119d0 [0x3bfb1100]>{type = mutable dict, count = 1,
entries =>
6 : <CFString 0x1c511a00 [0x3bfb1100]>{contents = "ApplicationType"} = <CFString 0x1c511970 [0x3bfb1100]>{contents = "User"}
}
Nov 29 20:51:53 mc_mobile_tunnel[277] <Notice>: (Note ) MC: mc_mobile_tunnel starting.
Nov 29 20:51:53 mc_mobile_tunnel[277] <Notice>: (Note ) MC: mc_mobile_tunnel shutting down.
Nov 29 20:51:53 mc_mobile_tunnel[278] <Notice>: (Note ) MC: mc_mobile_tunnel starting.
Nov 29 20:51:53 mc_mobile_tunnel[278] <Notice>: (Note ) MC: mc_mobile_tunnel shutting down.
Nov 29 20:51:55 mc_mobile_tunnel[280] <Notice>: (Note ) MC: mc_mobile_tunnel starting.
Nov 29 20:51:55 mc_mobile_tunnel[280] <Notice>: (Note ) MC: mc_mobile_tunnel shutting down.
Nov 29 20:52:01 iPhone4S mc_mobile_tunnel[282] <Notice>: (Note ) MC: mc_mobile_tunnel starting.
Nov 29 20:52:01 iPhone4S mc_mobile_tunnel[282] <Notice>: (Note ) MC: mc_mobile_tunnel shutting down.
this is because may be you are dismissing view just after dismissing picker:
[picker dismissModalViewControllerAnimated:YES];
[self dismissModalViewControllerAnimated:YES];
as you have used animated YES, the picker is not yet dismissed so either use new API
[picker dismissViewControllerAnimated:YES completion:^{
[self dismissModalViewControllerAnimated:YES];
}];
The App is crashes because in iOS6 [self dismissModalViewControllerAnimated:YES];
is deprecated you replace it with [picker dismissViewControllerAnimated:YES completion:nil]; may solve you issue.

iPhone app crashes randomly on device while connecting to remote server?

i have an app which post and get data using webservice it's working fine but while testing the app rigorously crashes with message Application Exited abnormally with signal 9(Killed) .
Mon Jul 16 21:07:55 unknown MyApp[167] <Warning>: NVVC Dealloc
Mon Jul 16 21:08:23 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:com.company.MyApp[0xe271]) Bug: launchd_core_logic.c:2688 (24132):10
Mon Jul 16 21:08:23 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:com.company.MyApp[0xe271]) Working around 5020256. Assuming the job crashed.
Mon Jul 16 21:08:23 unknown com.apple.launchd[1] <Warning>: (UIKitApplication:com.company.MyApp[0xe271]) Job appears to have crashed: Segmentation
fault
Mon Jul 16 21:08:23 unknown SpringBoard[29] <Warning>: Application 'MyApp' exited abnormally with signal 11: Segmentation fault
Mon Jul 16 21:09:04 unknown lockdownd[20] <Error>: (0x403000) handle_connection: Could not receive USB message #7 from Xcode. Killing connection
Mon Jul 16 22:00:39 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:com.apple.mobilemail[0x55fb]) Exited: Killed
Mon Jul 16 22:00:39 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:com.apple.mobilephone[0xa13c]) Exited: Killed
Mon Jul 16 22:00:39 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:com.MyApp.app[0x137]) Exited: Killed
Mon Jul 16 22:00:39 unknown com.apple.launchd[1] <Notice>: (com.apple.accessoryd) Exited: Killed
Mon Jul 16 22:00:41 unknown SpringBoard[29] <Warning>: Application 'Mail' exited abnormally with signal 9: Killed
Mon Jul 16 22:00:41 unknown SpringBoard[29] <Warning>: Memory level is not normal (15%). Delaying auto-relaunch of 'Mail' for 30 seconds. Mon Jul 16 22:00:41 unknown SpringBoard[29] <Warning>: Application 'app' exited abnormally with signal 9: Killed
Mon Jul 16 22:00:42 unknown SpringBoard[29] <Warning>: Application 'Phone' exited abnormally with signal 9: Killed
i googled around but i could not found any solution or reason for killing app.please Help me to resolve the issue.
Edit#2
Here i am adding some code where i am getting crash in my application.
#try {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSUserDefaults *defaults2 = [NSUserDefaults standardUserDefaults];
NSString *string = [NSString stringWithFormat:URL];
NSURL *url = [NSURL URLWithString:string];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: url];
// NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:synStr]];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
[connection release];
if(label != nil){
progressView = [[ProgressView showHUDAddedTo:self.tabBarController.view animated:YES]retain];
progressView.labelText = label;
}
[request release];
}
#catch (NSException * e) {
}
You're using NSURLConnection incorrectly. If you look here you can see that you are starting an asynchronous connection. It looks like you are releasing the connection object before it has finished, which is causing the segmentation fault.

iPad App crashes only when it is launched manually (from springboard). Memory issue suspected

I have been trying to solve this problem for 2 days now and it is driving me crazy. When Xcode launches the app it works fine, but If I manually launch the app from Springboard it crashes. The console prints out this:
Jan 20 15:26:29 unknown UIKitApplication:com.yourcompany.ThinClient[0x28cf][1119] <Notice>: ThinClient(1119,0x3db0000) malloc: *** error for object 0x643434: incorrect checksum for freed object - object was probably modified after being freed.
Jan 20 15:26:29 unknown UIKitApplication:com.yourcompany.ThinClient[0x28cf][1119] <Notice>: *** set a breakpoint in malloc_error_break to debug
Jan 20 15:26:29 unknown ThinClient[1119] <Error>: ThinClient(1119,0x3db0000) malloc: *** error for object 0x643434: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
The stack for the crashed thread (usually) looks like this, although sometimes it crashes in different spots:
Thread 5 Crashed:
0 libsystem_kernel.dylib 0x33d4da1c __pthread_kill + 8
1 libsystem_c.dylib 0x353523b4 pthread_kill + 52
2 libsystem_c.dylib 0x3534abf8 abort + 72
3 libsystem_c.dylib 0x3535e822 szone_error + 210
4 libsystem_c.dylib 0x3535e920 free_list_checksum_botch + 16
5 libsystem_c.dylib 0x35361722 tiny_malloc_from_free_list + 82
6 libsystem_c.dylib 0x35361e76 szone_malloc_should_clear + 166
7 libsystem_c.dylib 0x35362fd4 szone_malloc + 4
8 libsystem_c.dylib 0x35386230 malloc_zone_malloc + 48
9 libsystem_c.dylib 0x35386c2c malloc + 28
10 ThinClient 0x0000590c -[MySocket readBytes:] (MySocket.m:231)
11 ThinClient 0x00007b7e -[ThinServerTalker onSocket:readCallbackBytesWaiting:] (ThinServerTalker.m:362)
12 ThinClient 0x000057e2 ReadDataCB (MySocket.m:201)
13 CoreFoundation 0x33cca48a __CFSocketDoCallback + 334
14 CoreFoundation 0x33ccb4a2 __CFSocketPerformV0 + 78
15 CoreFoundation 0x33cc5a72 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 6
16 CoreFoundation 0x33cc7758 __CFRunLoopDoSources0 + 376
17 CoreFoundation 0x33cc84e4 __CFRunLoopRun + 224
18 CoreFoundation 0x33c58ebc CFRunLoopRunSpecific + 224
19 CoreFoundation 0x33c9b6d2 CFRunLoopRun + 42
20 ThinClient 0x00005656 -[MySocket _connect] (MySocket.m:160)
21 Foundation 0x33d71382 -[NSThread main] + 38
22 Foundation 0x33de35c6 __NSThread__main__ + 966
23 libsystem_c.dylib 0x3535230a _pthread_start + 242
24 libsystem_c.dylib 0x35353bb4 thread_start + 0
I suspect its from the application writing to memory that has already been freed, so I have already tried a few things:
I tried debugging the app with guard malloc, scribble, guard edges, zombie objects, malloc stack, etc..
I tried going to the code where the app crashed and finding an issue there ( i do not believe there is an issue there because the app crashes at different places, but they are all near each other)
I tried going through and commenting out all of my free() function calls.
I still have not found the problem! If anybody could please shed some light on this it would be much appreciated! Thanks! Any Suggestions?
Edit: The app will crash every time if it is launched from springboard, but if Xcode launches it, it will work fine.
I found the issue. I was returning a direct pointer to the bytes in a NSData object from a function. I simply replaced a function called "-(char*)getBytes" with a function called "-(NSData*)getDataCopy". Get data copy instead returns an autoreleased copy of the data class.
To reiterate:
I had this:
-(char*)getBytes{
return _data.bytes;}
and I replaced it with this
-(NSData*)getDataCopy{
return [NSData dataWithData:_data];
}
The issue was I was writing to memory that had already been released.

iPhone application crashes with Mprotect failed error (MonoTouch)

I have a problem with my iPhone application developed with MonoTouch.
I am developing an application that contacts a WCF Service, and when the WCF Service answer back, I update an UITableView with the returned data, when this is done it sends a new WCF async call, and when it answer back it updates the table again and so on.
The problem is that when it has done this in a variable amount of time, it crashes with an Mprotect failed error 12. This only happens when the application is running directly on the phone and not in the simulator.
I have tried to out comment where the update of the table happens, and making a Thread.Sleep(1000) before sending the next Async request to the WCF Service, but still the same error, but can run longer with out failing.
I contact the WCF Service through the "proxy" files, generated by SlSvcUtil.exe /noConfig http://mydomain/myservice.svc
My question is that can this error be avoid in a way or maybe with a workaround? Is it my fault, or is it a bug? It is actually because I shall use the application in my final school project, so it could be nice if I could fix it.
I post the console output, and a part from the crash report, but if you need more info please tell me, and I will post it. I am not a pro to use Mono or the MonoTouch environment it is my first time, so detailed responses would be nice.
Console output:
Mon Dec 27 20:37:17 tests-iPhone UIKitApplication:dk.test.iphone[0x1c3c][625] <Notice>: Mprotect failed at 0xa09a000 (length 1052672) with errno 12
Mon Dec 27 20:37:17 tests-iPhone UIKitApplication:dk.test.iphone[0x1c3c][625] <Notice>: Stacktrace:
Mon Dec 27 20:37:17 tests-iPhone UIKitApplication:dk.test.iphone[0x1c3c][625] <Notice>: at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <0xffffffff>
Mon Dec 27 20:37:17 tests-iPhone UIKitApplication:dk.test.iphone[0x1c3c][625] <Notice>: at MonoTouch.UIKit.UIApplication.Main (string[],string,string) <0x000e0>
Mon Dec 27 20:37:17 tests-iPhone UIKitApplication:dk.test.iphone[0x1c3c][625] <Notice>: at MonoTouch.UIKit.UIApplication.Main (string[]) <0x00023>
Mon Dec 27 20:37:17 tests-iPhone UIKitApplication:dk.test.iphone[0x1c3c][625] <Notice>: at iPhoneStdView.Application.Main (string[]) <0x0001b>
Mon Dec 27 20:37:17 tests-iPhone UIKitApplication:dk.test.iphone[0x1c3c][625] <Notice>: at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0x000c3>
Mon Dec 27 20:37:17 tests-iPhone UIKitApplication:dk.test.iphone[0x1c3c][625] <Notice>: Native stacktrace:
Mon Dec 27 20:37:18 tests-iPhone ReportCrash[635] <Notice>: Formulating crash report for process iPhoneNoNavigation[625]
Mon Dec 27 20:37:18 tests-iPhone com.apple.launchd[1] (UIKitApplication:dk.test.iphone[0x1c3c][625]) <Warning>: (UIKitApplication:dk.test.iphone[0x1c3c]) Job appears to have crashed: Abort trap
Mon Dec 27 20:37:18 tests-iPhone SpringBoard[27] <Warning>: Application 'iPhoneStdView' exited abnormally with signal 6: Abort trap
Crash report:
Thread 0 Crashed:
0 dyld 0x2fe08110 0x2fe00000 + 33040
1 libSystem.B.dylib 0x3020259e 0x301ff000 + 13726
2 libSystem.B.dylib 0x302531da 0x301ff000 + 344538
3 iPhoneNoNavigation 0x0051975c 0x1000 + 5343068
4 iPhoneNoNavigation 0x00538080 0x1000 + 5468288
5 libSystem.B.dylib 0x302765cc 0x301ff000 + 488908
6 libSystem.B.dylib 0x30201d64 0x301ff000 + 11620
7 CoreFoundation 0x3081fc38 0x307f8000 + 162872
8 CoreFoundation 0x3081f4c2 0x307f8000 + 160962
9 CoreFoundation 0x3081f270 0x307f8000 + 160368
10 CoreFoundation 0x3081f178 0x307f8000 + 160120
11 GraphicsServices 0x31e445ec 0x31e40000 + 17900
12 GraphicsServices 0x31e44698 0x31e40000 + 18072
13 UIKit 0x31e5111c 0x31e4d000 + 16668
14 UIKit 0x31e4f128 0x31e4d000 + 8488
15 iPhoneNoNavigation 0x0006e754 0x1000 + 448340
Thread 0 crashed with ARM Thread State:
r0: 0x35f4d17c r1: 0x302765a9 r2: 0x35989b04 r3: 0x0000000e
r4: 0x2fe29e78 r5: 0x07d17490 r6: 0x302765d3 r7: 0x2fffe24c
r8: 0x00000000 r9: 0x3598762c r10: 0x0000000d r11: 0x07d17470
ip: 0x3598762c sp: 0x2fffe240 lr: 0x3e08dc60 pc: 0x2fe08110
cpsr: 0x20000030
Error 12 is ENOMEM, you've exhausted all the memory available on the iphone.

GKSession alloc / release / alloc = leaks and crashes

I've got an app that throws out the GKSession and makes a new one under various conditions (connection timeout, session fails, etc.). I'm getting memory leaks, though, and it sometimes crashes after a few loops through the reconnect.
Here's my code:
- (void) netConnect:(id) sender {
NSLog(#"allocating GKSession");
currentSession = [[GKSession alloc] initWithSessionID:nil displayName:nil sessionMode:GKSessionModePeer];
currentSession.delegate = self;
currentSession.available = YES;
currentSession.disconnectTimeout = 0;
[currentSession setDataReceiveHandler: self withContext:nil];
}
- (void) netDisconnect:(id) sender {
NSLog(#"DISCONNECTING BY REQUEST");
[currentSession disconnectFromAllPeers];
[currentSession setAvailable:NO];
[currentSession setDelegate:nil];
[currentSession setDataReceiveHandler:nil withContext:nil];
[currentSession release];
currentSession = nil;
}
There's a timer that waits for a successful connection; if it doesn't get one, netDisconnect is called, followed by netConnect again after a 5-second NSTimer delay.
I'm getting leaked GKList, GKTable, and GKAutoPeerIDTable objects, and crashes like this (always occurs after the alloc) :
Date/Time: 2010-09-05 09:35:59.426 -0700
OS Version: iPhone OS 4.0.2 (8A400)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000a
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x0000286c objc_msgSend + 16
1 CoreFoundation 0x000756ea __CFCopyFormattingDescription + 174
2 CoreFoundation 0x00081c8e __CFStringAppendFormatCore + 8666
3 CoreFoundation 0x000146ac _CFStringCreateWithFormatAndArgumentsAux + 64
4 CoreFoundation 0x00014660 CFStringCreateWithFormatAndArguments + 16
5 CoreFoundation 0x0001463c CFStringCreateWithFormat + 16
6 SystemConfiguration 0x00003272 SCDynamicStoreCreateWithOptions + 62
7 SystemConfiguration 0x000033d0 SCDynamicStoreCreate + 12
8 GameKitServices 0x000020ce gckRegisterForNetworkChanges + 154
9 GameKitServices 0x000035c0 GCKSessionCreate + 788
10 GameKitServices 0x00035e7a -[GKSessionInternal initWithSessionID:displayName:session:sessionMode:] + 274
11 GameKit 0x0000fda8 -[GKSession initWithSessionID:displayName:sessionMode:] + 76
Here's another one:
Sun Sep 5 10:28:52 thinner someapp[424] <Warning>: allocating GKSession
Sun Sep 5 10:28:52 thinner someapp[424] <Error>: -[__NSCFData UTF8String]: unrecognized selector sent to instance 0x10a710
Sun Sep 5 10:28:52 thinner someapp[424] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData UTF8String]: unrecognized selector sent to instance 0x10a710'
*** Call stack at first throw:
(
0 CoreFoundation 0x31a9ffd3 __exceptionPreprocess + 114
1 libobjc.A.dylib 0x3428a8a5 objc_exception_throw + 24
2 CoreFoundation 0x31aa3a77 -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
3 CoreFoundation 0x31aa2f15 ___forwarding___ + 508
4 CoreFoundation 0x31a35680 _CF_forwarding_prep_0 + 48
5 GameKitServices 0x327aff13 -[GKSessionInternal initWithSessionID:displayName:session:sessionMode:] + 426
6 GameKit 0x31c15daf -[GKSession initWithSessionID:displayName:sessionMode:] + 82
7 someapp 0x0000584b -[MainViewController netConnect:] + 126
Questions:
• Is this the right way to release and re-allocate GKSessions?
• Should I not be tearing down and re-allocating GKSessions between connections to begin with?
This is a known issue. The workaround is to not pass in nil for the sessionID:
[[GKSession alloc] initWithSessionID:#"com.put.something.here" displayName:nil sessionMode:GKSessionModePeer];