Tuesday, July 14, 2015

Helpful CocoaPods

The classic and helpful AFNetworking
Github - CocoaPod pod "AFNetworking", "~> 2.0"

The robust and powerful JSON data network restful RESTKIT
Github - CocoaPod pod 'RestKit', '~> 0.24.0'
                                # Testing and Search are optional components
                                pod 'RestKit/Testing', '~> 0.24.0'
                                pod 'RestKit/Search',  '~> 0.24.0'

The nice JSON to/from NSDictionary template MANTLE
Github - CocoaPod  pod 'Mantle', '~>2.0.2'

The pretty much required facebook 1 2 3
Github - CocoaPod 'FBSDKCoreKit', 'FBSDKLoginKit', 'FBSDKShareKit' .

The ever helpful image downloader and cacher SDWebImage
Github - CocoaPod pod 'SDWebImage', '~>3.7'

Thursday, May 28, 2015

Random Storyboard Autolayout Situational Help

I'm just going to put random helpful links here that explain how to perform certain tasks in the xcode storyboard that might be helpful.

- Spreading out Items (like UIButtons) evenly. Helps to put them all in a separate UIView as well so you can move them all together.

- Simple Getting Started Tutorial with font sizing. Helps understand constraints that only work in certain devices as well as a nice font sizing section.

-How to unwind a segue with the push of a button. Frustrating if you don't know it. Explains how to setup and properly close a segue from any parent view controller. There is a programmatic version here.


Tuesday, May 26, 2015

Using CocoaPods and setting up Facebook SDK 4.1 in an xcode workspace in iOS8

Cocoapods are the new external framework. They are easy to setup, easy to update and easy to incorporate... one you have done it a few times. The most common external framework people use is the FacebookSDK. I will walk you through the basics of setting up a xcode workspace that incorporates the new facebookSDK which are now three parts; 'FBSDKCoreKit', 'FBSDKLoginKit', and 'FBSDKShareKit'.

I will probably go through some basic facebook usage in another post... maybe.

First you need to setup cocoapods. If you have not done so already, go into a terminal from your launchpad/utilities and type;
 $ sudo gem install cocoapods
This should use your integrated Ruby and setup cocoapods so you can use them whenever you want. It will most likely ask for your computer password and give you a warning but that is normal. Your mac should then  install a bunch of files and you are off to the races.

Next you will need to setup a work location. To be clean, create a new folder for your new app.
$ mkdir NewApp
$ cd NewApp
$ touch Podfile

You should be in your new app folder and in that folder should be an empty file called Podfile. This file is the instructions for cocoapods on what pods you want installed for this particular app. Since we want the app to have the new facebook pods installed, open up the Podfile in whichever prefered editor you want and copy this in;

source 'https://github.com/CocoaPods/Specs.git'
xcodeproj 'NewApp'
platform :ios, '7.0'
#Facebook Stuff
pod 'FBSDKCoreKit', '~> 4.1'
pod 'FBSDKLoginKit', '~> 4.1'
pod 'FBSDKShareKit', '~> 4.1'

What this does; The first line is to tell Cocoapods where on the internet you wish to look for the pods. The second line says what project you want your pods to work with. The third line says what target you want to setup. The lines with a # at the beginning are just comments and the last three lines are the actual facebook pods you wish to install into your workspace. Close this up and open up xcode.

In xcode, create a new project called NewApp (or whatever you decided to call it in the other areas) and put it in the same directory as the Podfile. Now go back to your terminal session and type;
$pod install

If everything was done correctly, you should see some green command lines installing the facebook pods and then the folder should also have a new xcworkspace file. Open up that file and you should see both your project and and 'Pods' in your workspace directory in xcode.

And you are done!

Why do this? Well, not only can you copy and paste this into all future projects but you can also update the pods at any point by just typing 'pod install' or 'pod update'. You can also create your own local pods and do the same thing. The way to do that is just specify a local directory for the pod you wish to incorporate;


#pod 'D2TSounds', :path => '/Users/yourname/Documents/CocoaPods/D2TSounds'

You might need to do a little setup for the local files but if you have several items that you use a lot, this will save you a lot of time in the long run.

Helpful links;
Cocoapods initial setup
Cocoapod pod link page
Facebook Login
Facebook Sharing
Facebook App Links
Facebook Graph API


Tuesday, February 10, 2015

Using blocks in objective-c iOS7 and iOS8

blocks are a godsend and still people are reserved in using it. Perhaps it is because they don't know how to set it up. Here is a quick example on how to set it up.

In the .h file of whatever you are creating, make a new typedef for the block;

typedef void(^myCompletion)(BOOL complete);

This line shows that this is a "myCompletion" block and has one value going into it which a bool called complete. 

Next in the .h file create the method you want with a completion block;

-(void)doMyStuff withCompletion:(myCompletion)compBlock;

Now all you have to do is create it in your .m file;

-(void)doMyStuff withCompletion:(myCompletion)compBlock{
     //do the stuff you want to do 
     if (compBlock != nil) {
         compBlock(YES);
     }
}

This will do the method and then check if the compBlock is nil (protection) and if it is not nil, perform that block of functions as well. 

Technically you can do the block anywhere in the code, I am just using completion as an example since most of the time, that is where it is used. 

Now you actually want to use this method? Simple;

[myMethod doMyStuff withCompletion:^(BOOL complete) {
     if (complete){

          self.navController.topViewController.navigationItem.titleView = logoView; 
     }
}];

and there you have it. 

if you want another version, you can look here.
Stanford also has a nice video about using existing blocks here.


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.