After app goes to background animation stops
1
2
3
This is just how Apple handles animations. CAAnimations are stopped and removed when the app is backgrounded. If you pause the animation before the app is backgrounded the state will be preserved so you can play again when the app is foregrounded.
For the best results, pause the animation when the app is backgrounded by either listening to the UIApplicationDidEnterBackgroundNotification or viewWillDissapear, and then play again when the app is foregrounded.
Managing different Environments using XCode Build Schemes and Configurations
iPhone:Programmatically compressing recorded video to share?
If you want to compress the video for remote sharing and keep the original quality for local storage on the iPhone, you should look into AVAssetExportSession or AVAssetWriter.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
- (void)convertVideoToLowQuailtyWithInputURL:(NSURL*)inputURL
outputURL:(NSURL*)outputURL
handler:(void (^)(AVAssetExportSession*))handler
{
[[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality];
exportSession.outputURL = outputURL;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
[exportSession exportAsynchronouslyWithCompletionHandler:^(void)
{
handler(exportSession);
[exportSession release];
}];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSURL *outputURL = [NSURL fileURLWithPath:@"/Users/josh/Desktop/output.mov"];
[self convertVideoToLowQuailtyWithInputURL:videoURL outputURL:outputURL handler:^(AVAssetExportSession *exportSession)
{
if (exportSession.status == AVAssetExportSessionStatusCompleted)
{
printf("completed\n");
}
else
{
printf("error\n");
}
}];
}
How to debug “message sent to deallocated instance” in Xcode 4?
In addition to Jeff’s great answer; to do almost the same thing, but without having to open Instruments or profile your App, you can set NSZombieEnabled, MallocStackLogging, and guard malloc in the debugger. Then, when your App crashes, type this in the gdb console:
1
2
3
4
5
6
# gdb
info malloc-history 0x543216
#lldb
`script import lldb.macosx.heap` or `command script import lldb.macosx.heap`
malloc_info --stack-history 0x7c506a00
When to use Semaphore instead of Dispatch Group?
Dispatch groups are used when you have a load of things you want to do that can all happen at once, but you need to wait for them all to finish before doing something else.
Semaphores can be used for the above but they are general purpose synchronisation objects and can be used for many other purposes too. The concept of a semaphore is not limited to Apple and can be found in many operating systems.
In general, a semaphore has a value which is a non negative integer and two operations:
- wait If the value is not zero, decrement it, otherwise block until something signals the semaphore.
- signal If there are threads waiting, unblock one of them, otherwise increment the value.