32

restkit is using in a different way the oauth2 protocol, I need to change the code to be able to use it in my way:

From:

// OAuth 2 valid request
if (self.authenticationType == RKRequestAuthenticationTypeOAuth2) {
    NSString *authorizationString = [NSString stringWithFormat:@"OAuth2 %@", self.OAuth2AccessToken];
    [_URLRequest setValue:authorizationString forHTTPHeaderField:@"Authorization"];
}

to:

// OAuth 2 valid request
if (self.authenticationType == RKRequestAuthenticationTypeOAuth2) {
    NSString *authorizationString = [NSString stringWithFormat:@"Bearer %@", self.OAuth2AccessToken];
    [_URLRequest setValue:authorizationString forHTTPHeaderField:@"Authorization"];
}

Use of "Bearer" instead of "Oauth2" ....

I'm using CocoaPods to import restkit in my project.

Can I fork Restkit repository on github and use the fork via CocoaPod instead of the official version?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Nicolas Henin
  • 3,244
  • 2
  • 21
  • 42
  • 1
    If you think your changes make sense try to make a pull request to the original project. As a bonus you won't have to worry about maintaining your fork in the future. – Rivera Jun 06 '14 at 02:50

2 Answers2

90

You certainly can. Take a look at https://github.com/CocoaPods/CocoaPods/wiki/Dependency-declaration-options

If RestKit included its .podspec file in the repository then you could just change your Podfile to point to your fork i.e.

pod 'RestKit', :git => 'https://github.com/you/RestKit.git'

Unfortunately RestKit does not include its .podspec. Instead copy RestKit.podspec from https://github.com/CocoaPods/Specs/blob/master/RestKit/0.10.2/RestKit.podspec and add it to your project. Edit the .podspec to use your fork as its source. You can then specify a local .podspec in your Podfile:

pod 'RestKit', :podspec => 'local/path/to/RestKit.podspec'

Alternately you might just add this .podspec to your fork and use the former dependency declaration.

Jonah
  • 17,918
  • 1
  • 43
  • 70
4

Even though this question has an accepted answer, I wanted to add an alternative approach. At some time (I believe after this question was asked) the ability to have local references in Podfiles (and not just Podspecs) was added to Cocoapods.

Rather than creating custom creating public forks in Github and custom Podspecs, I find it easier to:

  1. Clone the Github library locally.
  2. Create a new local branch where I make the changes that I need in that library that are specific to my project.
  3. Modify my Podfile to point to that local directory and local branch:

    pod 'FXForms', :path => '~/Documents/Projects/RestKit', :branch => 'mybranch'
    

This makes it easy for me to incorporate any new versions of the library (by just pulling them from origin and then merging them into my local branch).

David Ogren
  • 4,396
  • 1
  • 19
  • 29
  • 4
    This solution only works if you build from your own machine. If you're in a team or have a build server this won't work. – Rool Paap Apr 30 '15 at 13:18