Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

fix build #13

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "libs/asi-http-request"]
path = libs/asi-http-request
url = https://github.com/pokeb/asi-http-request.git
[submodule "libs/facebook"]
path = libs/facebook
url = https://github.com/facebook/facebook-ios-sdk.git
[submodule "libs/nimbus"]
path = libs/nimbus
url = https://github.com/mobomo/nimbus.git
Expand Down
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,25 @@ The following libraries are included as submodules:

* [SVPullToRefresh][]
* [Nimbus][]
* [Facebook SDK for iOS][fb]

To intialize submodules, run:

git submodule update --init

To build Facebook, `cd` into `libs/facebook` and run
`./scripts/build_facebook_ios_sdk_static_lib.sh`. This will build the
static library used by the app.

### Binary Libraries

The following libraries must be downloaded and installed manually:

* [libUAirship][] - Urban Airship library for iOS
* [Urban Airship library for iOS][ua]
* [Google Analytics SDK for iOS][ga]
* [Facebook SDK for iOS][fb]

To install Urban Airship, download the SDK and place the entire
`Airship` directory inside of `libs/`.

To install Google Analytics, download the SDK and place the entire
`Google Analytics SDK` directory inside of `libs/`.
To install Google Analytics, download the [Standalone SDK][gasdk], rename the `Library` directory to `GoogleAnalytics`, and place it inside of `libs/`.

To install the Facebook SDK, download and install the package, copy the FacebookSDK.framework directory into `libs/`, and drag it into the the `Frameworks` group in your project.

### Feeds

Expand All @@ -93,6 +90,17 @@ The optimal size for display is chosen depending on the context (e.g. 640px
for article feeds on the iPhone 4, or ~70px for photo gallery thumbnails on the
iPhone 3GS) and screen density.

### Search

Search functionality on WhiteHouse.gov and in the White House for iOS
mobile app relies on USASearch, a hosted site search service provided by
the U.S. General Services Administration (GSA). Federal, state, local,
tribal, or territorial government websites may use this service at no cost.
For details on incorporating USASearch into .Gov sites, or for examples of
the API and how it functions, see [USASearch: About](http://usasearch.howto.gov/about-us)
and [USASearch: How (and When) to Use the Search API](http://usasearch.howto.gov/post/36743437542/how-and-when-to-use-the-search-api).



NOTE: Setting up the application and configuring it for use in your
organization's context requires iOS development experience. The
Expand Down Expand Up @@ -156,15 +164,15 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



[libUAirship]: http://urbanairship.com/resources/
[ua]: http://urbanairship.com/resources/developer-resources
[fb]: https://developers.facebook.com/docs/ios/
[ga]: https://developers.google.com/analytics/devguides/collection/ios/resources
[gasdk]: http://dl.google.com/dl/gaformobileapps/GoogleAnalyticsiOS_2.0beta4.zip
[CustomBadge]: http://www.spaulus.com/2011/04/custombadge-2-0-retina-ready-scalable-light-reflex/
[Underscore.js]: http://underscorejs.org/
[Zepto.js]: http://zeptojs.com/
[DTCustomColoredAccessory]: http://www.cocoanetics.com/2010/10/custom-colored-disclosure-indicators/
[SVPullToRefresh]: https://github.com/samvermette/SVPullToRefresh
[fb]: https://github.com/facebook/facebook-ios-sdk
[Nimbus]: https://github.com/jverkoey/nimbus

[forking]: https://help.github.com/articles/fork-a-repo
[basic tutorial]: https://help.github.com/articles/set-up-git
486 changes: 31 additions & 455 deletions WhiteHouseApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions WhiteHouseApp/AirshipConfig.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DEVELOPMENT_APP_KEY</key>
<string>your development key</string>
<key>DEVELOPMENT_APP_SECRET</key>
<string>your development secret</string>
<key>PRODUCTION_APP_KEY</key>
<string>your production key</string>
<key>PRODUCTION_APP_SECRET</key>
<string>your production secret</string>
<key>APP_STORE_OR_AD_HOC_BUILD</key>
<false/>
<key>inProduction</key>
<false/>
<key>developmentAppKey</key>
<string>Your Development App Key</string>
<key>developmentAppSecret</key>
<string>Your Development App Secret</string>
<key>productionAppKey</key>
<string>Your Production App Key</string>
<key>productionAppSecret</key>
<string>Your Production App Secret</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion WhiteHouseApp/UIViewController+WHFeedItemPresentation.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ - (NSString *)trackingPathComponent

- (void)displayFeedItem:(WHFeedItem *)item
{
[[GANTracker sharedTracker] trackPageview:[NSString stringWithFormat:@"%@/%@", [self trackingPathComponent], [item trackingPathCompontent]] withError:nil];
[[[GAI sharedInstance] defaultTracker] sendView:[NSString stringWithFormat:@"%@/%@", [self trackingPathComponent], [item trackingPathCompontent]]];

if (item.enclosureURL) {
NSString *host = item.enclosureURL.host;
Expand Down
6 changes: 2 additions & 4 deletions WhiteHouseApp/WHAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,20 @@
//

#import <UIKit/UIKit.h>

#import "Facebook.h"
#import <FacebookSDK/FacebookSDK.h>
#import "WHRootMenuViewController.h"
#import "WHLiveBarController.h"
#import "WHRevealViewController.h"
#import "WHFeedViewController.h"
#import "WHLiveController.h"

@interface WHAppDelegate : UIResponder <UIApplicationDelegate, FBSessionDelegate, FBDialogDelegate, UIAlertViewDelegate> {
@interface WHAppDelegate : UIResponder <UIApplicationDelegate, UIAlertViewDelegate> {
int liveSectionMenuIndex;
}

@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, strong) WHLiveBarController *liveBarController;

- (void)initFacebook;
- (void)shareOnFacebook:(WHFeedItem *)item;

@end
192 changes: 99 additions & 93 deletions WhiteHouseApp/WHAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ @interface WHAppDelegate ()
@property (nonatomic, strong) WHRootMenuViewController *menu;
@property (nonatomic, strong) WHFeedViewController *liveSectionViewController;
@property (nonatomic, strong) WHLiveController *liveController;
@property (nonatomic, strong) Facebook *facebook;
@property (nonatomic, strong) NSDictionary *pendingNotification;
- (void)initFacebook;
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error;
- (NSDictionary*)parseURLParams:(NSString *)query;
@end


Expand All @@ -63,7 +65,6 @@ @implementation WHAppDelegate
@synthesize liveSectionViewController = _liveViewController;
@synthesize liveController;
@synthesize liveBarController;
@synthesize facebook;
@synthesize pendingNotification;

- (void)configureAppearance
Expand Down Expand Up @@ -205,15 +206,18 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

[self configureAppearance];


// configure Google Analytics
NSString *accountID = AppConfig(@"GANAccountID");
GANTracker *tracker = [GANTracker sharedTracker];
[GAI sharedInstance].dispatchInterval = 30;

id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:accountID];
tracker.anonymize = YES;
[tracker sendView:@"/LAUNCH"];

// do not send full IP addresses
tracker.anonymizeIp = YES;
[tracker startTrackerWithAccountID:accountID dispatchPeriod:30 delegate:nil];
[tracker trackPageview:@"/LAUNCH" withError:nil];
// check for cached facebook session
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
[self initFacebook];
}

self.menu = [self loadMenu];
UIViewController *defaultViewController = [[self.menu.menuItems objectAtIndex:0] viewController];
Expand Down Expand Up @@ -243,22 +247,24 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
return YES;
}


- (void)initAirship:(UIApplication *)application
{
[UAirship takeOff:[NSDictionary dictionary]];

// Register for notifications
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBAppEvents activateApp];
[FBSession.activeSession handleDidBecomeActive];
}


- (void)applicationWillTerminate:(UIApplication *)application {
[UAirship land];
[FBSession.activeSession close];
}

- (void)initAirship:(UIApplication *)application
{
[UAirship takeOff];

// Register for notifications
[UAPush shared].notificationTypes = (UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert);
}

#pragma mark Push notification handling

Expand Down Expand Up @@ -381,102 +387,102 @@ - (void)revealToggle:(id)sender
[self.reveal setMenuVisible:YES wantsFullWidth:NO];
}

//#pragma mark - Facebook methods

#pragma mark - Facebook methods


- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [self.facebook handleOpenURL:url];
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [FBSession.activeSession handleOpenURL:url];
}


- (void)initFacebook
{
if (self.facebook) {
return;
}

NSString *fbID = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FacebookAppID"];
if (fbID) {
// facebook
self.facebook = [[Facebook alloc] initWithAppId:fbID andDelegate:self];
}

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
self.facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
self.facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}

self.facebook.sessionDelegate = self;

[self.facebook authorize:nil];
}


- (void)updateFacebookToken:(NSString *)accessToken expiresAt:(NSDate *)expiresAt
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:accessToken forKey:@"FBAccessTokenKey"];
[defaults setObject:expiresAt forKey:@"FBExpirationDateKey"];
[defaults synchronize];
}


- (void)fbDidLogin
{
[self updateFacebookToken:facebook.accessToken expiresAt:facebook.expirationDate];
}


- (void)fbDidNotLogin:(BOOL)cancelled
{
NSLog(@"User did not log in to Facebook");
}


- (void)fbDidLogout
{
NSLog(@"User did log out from Facebook");
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:NO
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
}


- (void)fbSessionInvalidated
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState)state
error:(NSError *)error
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults removeObjectForKey:@"FBAccessTokenKey"];
[defaults removeObjectForKey:@"FBExpirationDateKey"];
[defaults synchronize];
switch (state) {
case FBSessionStateOpen:
NSLog(@"User has logged in to Facebook (or cached token was available)");
break;
case FBSessionStateOpenTokenExtended:
NSLog(@"Facebook token has been extended");
break;
case FBSessionStateClosedLoginFailed:
NSLog(@"Facebook login attempt failed");
[FBSession.activeSession closeAndClearTokenInformation];
break;
case FBSessionStateClosed:
NSLog(@"Facebook session was closed");
break;
default:
break;
}

if (error) {
NSLog(@"Facebook session state change error: %@", error.localizedDescription);
}
}


- (void)fbDidExtendToken:(NSString*)accessToken
expiresAt:(NSDate*)expiresAt
{
[self updateFacebookToken:accessToken expiresAt:expiresAt];
- (NSDictionary*)parseURLParams:(NSString *)query {
NSArray *pairs = [query componentsSeparatedByString:@"&"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
for (NSString *pair in pairs) {
NSArray *kv = [pair componentsSeparatedByString:@"="];
NSString *val = [kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
params[kv[0]] = val;
}
return params;
}


- (void)shareOnFacebook:(WHFeedItem *)item
{
[self initFacebook];
NSMutableDictionary *sharingParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:[item.link absoluteString], @"link", item.title, @"name", nil];
if (!FBSession.activeSession.isOpen) {
[self initFacebook];
}

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:[item.link absoluteString], @"link", item.title, @"name", nil];

// look for pictures in the post
WHMediaElement *media = [item bestContentForWidth:0];

if (media == nil) {
media = [item bestThumbnailForWidth:0];
}

if (media) {
[sharingParams setObject:[media.URL absoluteString] forKey:@"picture"];
[params setObject:[media.URL absoluteString] forKey:@"picture"];
}

[self.facebook dialog:@"feed" andParams:sharingParams andDelegate:self];

[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Error launching the dialog or publishing story
NSLog(@"Error publishing Facebook story: %@", error.localizedDescription);
return;
}
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(@"User canceled Facebook story publishing");
return;
}
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:@"post_id"]) {
// User clicked the Cancel button
NSLog(@"User canceled Facebook story publishing");
return;
}
NSLog(@"Posted Facebook story, id: %@", [urlParams valueForKey:@"post_id"]);
}];
}


@end
Loading