Thursday, December 11, 2014

Possible Problems with UICollectionView Animations not working when rotating.

If you are using UICollectionView and would like it to animate moving the cells around when rotating the device but it is not working, there might be an important reason. The animation methods (-(UICollectionViewLayoutAttributes*) initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *) itemIndexPath and -(UICollectionViewLayoutAttributes*) finalLayoutAttributesForDisappearingItemAtIndexPath: (NSIndexPath *) itemIndexPath ) will only get calls if you are using autolayout. If you are using frames to move things around, it won't call the methods in questions when rotating. Turn on the autolayout by calling (    self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight) on the collection view and it should start calling the methods correctly when rotating. You might also have to set this for the parents as well.

The down side is, if you are changing the size of the cells as well, you might have to redo them using contraints instead of frames.

If you are interesting in animations at all with UICollectionViews, I suggest you go here

Sunday, September 14, 2014

Grabbing call notifications in iOS7

Looks like there is not much in the way of documentation for how to do this so I am going to create one here.

Sometimes people get calls on their phone, I know this is crazy but it can happen. What you should do about it is up to you but how can you let your app know when this happens? Well I can help with that.

in your .h file, add the following.


#import <CoreTelephony/CTCallCenter.h>

@property (nonatomic, strong) CTCallCenter* callCenter;

you need to set the property as if you don't have anything holding on to the connection, it will disappear on your. Gotta love ARC!

in the .m file, here is your master method;

#pragma mark - phone call interrupts
-(void) setupPhoneNotification{
    float static playerVolume;
    self.callCenter = [[CTCallCenter alloc] init];
    self.callCenter.callEventHandler=^(CTCall* call)
    {
        
        if(call.callState == CTCallStateDialing)
        {
            //The call state, before connection is established, when the user initiates the call.
            NSLog(@"Call is dailing");
        }
        if(call.callState == CTCallStateIncoming)
        {
            //The call state, before connection is established, when a call is incoming but not yet answered by the user.
            NSLog(@"Call is Coming");
        }
        
        if(call.callState == CTCallStateConnected)
        {
            //The call state when the call is fully established for all parties involved.
            NSLog(@"Call Connected");
        }
        
        if(call.callState == CTCallStateDisconnected)
        {
            //The call state Ended.
            NSLog(@"Call Ended");
        } 
    };
}

And there you have it. Do whatever you need to do in the block, possibly send a trigger event or notifcation and then you are off to the races. Have fun!

Highjacking a url request via Charles 3.9.2

- install charles
- run what you want that requests data
- copy and edit that information to conform with what you want it to
- save it in a text file (make sure it has no extra stuff like rich text or html headers)
- right click on Charles where the request happened
- choose "map local" which is usually on the bottom of the list
- choose the file you created

From now on, it will use that file instead of what it gets back from the URL request!

Now if you want to add this capability to your devices
- open up your settings
- choose the same wifi as your computer
- go to the bottom of the of wifi setting for that and edit the HTTP PROXY info
- change the "server" to your computer IP and the Port to 8888 (Charles uses this)
- you should get a warning in Charles asking if you want a new device connected to it, say yes
- make sure you have no VPN setup or it may conflict

From now on, your device will also get interrupted by Charles and will get the response that you created instead of the URL response. 

Monday, January 6, 2014

iOS converting most audio files into iOS friendly audio files

iOS is both very generous and very picky when it comes to audio. It can play almost anything without issue but when you want to play audio in certain ways, it just won't work. Here is a quick way to convert your existing audio files to iOS friendly .caf files;

1) on the folder with your sound files in it, select it an choose 'copy'
2) press "Command-space" to open up the fast launch option on your mac
3) type "terminal" to open up a command terminal session
4) type "cd " and then "command-v" to paste the location of the directory and press enter to go to that directory
5) you can press "cd" or "ls" to confirm you are in the right directory, you should see the files you want to change there
6) type "afconvert -f caff -d LEI16@44100 -c 1 in.wav out.caf"
or "afconvert in.mp3 out.caf -d ima4 -f caff -v" with "in" being your file you want to change and "out" being the file you want to change it to.

And you are done! Don't forget to copy the new files into your application.