Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
a6910ce3
Commit
a6910ce3
authored
Nov 09, 2011
by
Eloy Duran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Import the updated AFNetworking iOS example.
parent
3c03a9d1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
766 additions
and
0 deletions
+766
-0
project.pbxproj
...xample/AFNetworking iOS Example.xcodeproj/project.pbxproj
+0
-0
AppDelegate.h
examples/AFNetworking iOS Example/AppDelegate.h
+32
-0
AppDelegate.m
examples/AFNetworking iOS Example/AppDelegate.m
+55
-0
AFGowallaAPIClient.h
...les/AFNetworking iOS Example/Classes/AFGowallaAPIClient.h
+31
-0
AFGowallaAPIClient.m
...les/AFNetworking iOS Example/Classes/AFGowallaAPIClient.m
+67
-0
NearbySpotsViewController.h
...S Example/Classes/Controllers/NearbySpotsViewController.h
+32
-0
NearbySpotsViewController.m
...S Example/Classes/Controllers/NearbySpotsViewController.m
+191
-0
Spot.h
examples/AFNetworking iOS Example/Classes/Models/Spot.h
+43
-0
Spot.m
examples/AFNetworking iOS Example/Classes/Models/Spot.m
+84
-0
SpotTableViewCell.h
...FNetworking iOS Example/Classes/Views/SpotTableViewCell.h
+31
-0
SpotTableViewCell.m
...FNetworking iOS Example/Classes/Views/SpotTableViewCell.m
+97
-0
placeholder-stamp.png
...les/AFNetworking iOS Example/Images/placeholder-stamp.png
+0
-0
placeholder-stamp@2x.png
.../AFNetworking iOS Example/Images/placeholder-stamp@2x.png
+0
-0
Info.plist
examples/AFNetworking iOS Example/Info.plist
+34
-0
Podfile
examples/AFNetworking iOS Example/Podfile
+29
-0
Prefix.pch
examples/AFNetworking iOS Example/Prefix.pch
+10
-0
main.m
examples/AFNetworking iOS Example/main.m
+30
-0
No files found.
examples/AFNetworking iOS Example/AFNetworking iOS Example.xcodeproj/project.pbxproj
0 → 100644
View file @
a6910ce3
This diff is collapsed.
Click to expand it.
examples/AFNetworking iOS Example/AppDelegate.h
0 → 100644
View file @
a6910ce3
// AFNetworkingExampleAppDelegate.h
//
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import <UIKit/UIKit.h>
@interface
AppDelegate
:
NSObject
<
UIApplicationDelegate
>
{
}
@property
(
nonatomic
,
retain
)
UIWindow
*
window
;
@property
(
nonatomic
,
retain
)
UINavigationController
*
navigationController
;
@end
examples/AFNetworking iOS Example/AppDelegate.m
0 → 100644
View file @
a6910ce3
// AFNetworkingExampleAppDelegate.m
//
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import "AppDelegate.h"
#import "NearbySpotsViewController.h"
#import "AFNetworkActivityIndicatorManager.h"
@implementation
AppDelegate
@synthesize
window
=
_window
;
@synthesize
navigationController
=
_navigationController
;
-
(
BOOL
)
application
:(
UIApplication
*
)
application
didFinishLaunchingWithOptions
:(
NSDictionary
*
)
launchOptions
{
NSURLCache
*
URLCache
=
[[[
NSURLCache
alloc
]
initWithMemoryCapacity
:
1024
*
1024
diskCapacity
:
1024
*
1024
*
5
diskPath
:
nil
]
autorelease
];
[
NSURLCache
setSharedURLCache
:
URLCache
];
[[
AFNetworkActivityIndicatorManager
sharedManager
]
setEnabled
:
YES
];
UITableViewController
*
viewController
=
[[[
NearbySpotsViewController
alloc
]
init
]
autorelease
];
self
.
navigationController
=
[[[
UINavigationController
alloc
]
initWithRootViewController
:
viewController
]
autorelease
];
self
.
window
=
[[[
UIWindow
alloc
]
initWithFrame
:[[
UIScreen
mainScreen
]
bounds
]]
autorelease
];
self
.
window
.
backgroundColor
=
[
UIColor
whiteColor
];
self
.
window
.
rootViewController
=
self
.
navigationController
;
[
self
.
window
makeKeyAndVisible
];
return
YES
;
}
-
(
void
)
dealloc
{
[
_window
release
];
[
_navigationController
release
];
[
super
dealloc
];
}
@end
examples/AFNetworking iOS Example/Classes/AFGowallaAPIClient.h
0 → 100644
View file @
a6910ce3
// AFGowallaAPI.h
//
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import <Foundation/Foundation.h>
#import "AFHTTPClient.h"
extern
NSString
*
const
kAFGowallaClientID
;
extern
NSString
*
const
kAFGowallaBaseURLString
;
@interface
AFGowallaAPIClient
:
AFHTTPClient
+
(
AFGowallaAPIClient
*
)
sharedClient
;
@end
examples/AFNetworking iOS Example/Classes/AFGowallaAPIClient.m
0 → 100644
View file @
a6910ce3
// AFGowallaAPI.m
//
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import "AFGowallaAPIClient.h"
#import "AFJSONRequestOperation.h"
// Replace this with your own API Key, available at http://api.gowalla.com/api/keys/
NSString
*
const
kAFGowallaClientID
=
@"e7ccb7d3d2414eb2af4663fc91eb2793"
;
NSString
*
const
kAFGowallaBaseURLString
=
@"https://api.gowalla.com/"
;
@implementation
AFGowallaAPIClient
+
(
AFGowallaAPIClient
*
)
sharedClient
{
static
AFGowallaAPIClient
*
_sharedClient
=
nil
;
static
dispatch_once_t
oncePredicate
;
dispatch_once
(
&
oncePredicate
,
^
{
_sharedClient
=
[[
self
alloc
]
initWithBaseURL
:[
NSURL
URLWithString
:
kAFGowallaBaseURLString
]];
});
return
_sharedClient
;
}
-
(
id
)
initWithBaseURL
:
(
NSURL
*
)
url
{
self
=
[
super
initWithBaseURL
:
url
];
if
(
!
self
)
{
return
nil
;
}
[
self
registerHTTPOperationClass
:[
AFJSONRequestOperation
class
]];
// Accept HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
[
self
setDefaultHeader
:
@"Accept"
value
:
@"application/json"
];
// X-Gowalla-API-Key HTTP Header; see http://api.gowalla.com/api/docs
[
self
setDefaultHeader
:
@"X-Gowalla-API-Key"
value
:
kAFGowallaClientID
];
// X-Gowalla-API-Version HTTP Header; see http://api.gowalla.com/api/docs
[
self
setDefaultHeader
:
@"X-Gowalla-API-Version"
value
:
@"1"
];
// X-UDID HTTP Header
[
self
setDefaultHeader
:
@"X-UDID"
value
:[[
UIDevice
currentDevice
]
uniqueIdentifier
]];
return
self
;
}
@end
examples/AFNetworking iOS Example/Classes/Controllers/NearbySpotsViewController.h
0 → 100644
View file @
a6910ce3
// NearbySpotsViewController.h
//
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface
NearbySpotsViewController
:
UITableViewController
<
CLLocationManagerDelegate
>
{
NSArray
*
_nearbySpots
;
CLLocationManager
*
_locationManager
;
UIActivityIndicatorView
*
_activityIndicatorView
;
}
@end
examples/AFNetworking iOS Example/Classes/Controllers/NearbySpotsViewController.m
0 → 100644
View file @
a6910ce3
// NearbySpotsViewController.m
//
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import "NearbySpotsViewController.h"
#import "Spot.h"
#import "SpotTableViewCell.h"
#import "TTTLocationFormatter.h"
#import "AFImageCache.h"
#import "UIImageView+AFNetworking.h"
@interface
NearbySpotsViewController
()
@property
(
readwrite
,
nonatomic
,
retain
)
NSArray
*
nearbySpots
;
@property
(
readwrite
,
nonatomic
,
retain
)
CLLocationManager
*
locationManager
;
@property
(
readwrite
,
nonatomic
,
retain
)
UIActivityIndicatorView
*
activityIndicatorView
;
-
(
void
)
loadSpotsForLocation
:(
CLLocation
*
)
location
;
-
(
void
)
refresh
:(
id
)
sender
;
@end
@implementation
NearbySpotsViewController
@synthesize
nearbySpots
=
_spots
;
@synthesize
locationManager
=
_locationManager
;
@synthesize
activityIndicatorView
=
_activityIndicatorView
;
-
(
id
)
init
{
self
=
[
super
init
];
if
(
!
self
)
{
return
nil
;
}
self
.
nearbySpots
=
[
NSArray
array
];
self
.
locationManager
=
[[[
CLLocationManager
alloc
]
init
]
autorelease
];
self
.
locationManager
.
delegate
=
self
;
self
.
locationManager
.
distanceFilter
=
80
.
0
;
return
self
;
}
-
(
void
)
dealloc
{
[
_spots
release
];
[
_locationManager
release
];
[
_activityIndicatorView
release
];
[
super
dealloc
];
}
-
(
void
)
loadSpotsForLocation
:
(
CLLocation
*
)
location
{
[
self
.
activityIndicatorView
startAnimating
];
self
.
navigationItem
.
rightBarButtonItem
.
enabled
=
NO
;
[
Spot
spotsWithURLString
:
@"/spots"
near
:
location
parameters
:
[
NSDictionary
dictionaryWithObject
:
@"128"
forKey
:
@"per_page"
]
block
:^
(
NSArray
*
records
)
{
self
.
nearbySpots
=
[
records
sortedArrayUsingComparator
:
^
NSComparisonResult
(
id
obj1
,
id
obj2
)
{
CLLocationDistance
d1
=
[[(
Spot
*
)
obj1
location
]
distanceFromLocation
:
location
];
CLLocationDistance
d2
=
[[(
Spot
*
)
obj2
location
]
distanceFromLocation
:
location
];
if
(
d1
<
d2
)
{
return
NSOrderedAscending
;
}
else
if
(
d1
>
d2
)
{
return
NSOrderedDescending
;
}
else
{
return
NSOrderedSame
;
}
}];
[
self
.
tableView
reloadData
];
[
self
.
activityIndicatorView
stopAnimating
];
self
.
navigationItem
.
rightBarButtonItem
.
enabled
=
YES
;
}];
}
#pragma mark - UIViewController
-
(
void
)
viewDidLoad
{
[
super
viewDidLoad
];
self
.
title
=
NSLocalizedString
(
@"AFNetworking"
,
nil
);
self
.
activityIndicatorView
=
[[[
UIActivityIndicatorView
alloc
]
initWithActivityIndicatorStyle
:
UIActivityIndicatorViewStyleWhite
]
autorelease
];
self
.
activityIndicatorView
.
hidesWhenStopped
=
YES
;
self
.
navigationItem
.
leftBarButtonItem
=
[[[
UIBarButtonItem
alloc
]
initWithCustomView
:
self
.
activityIndicatorView
]
autorelease
];
self
.
navigationItem
.
rightBarButtonItem
=
[[[
UIBarButtonItem
alloc
]
initWithBarButtonSystemItem
:
UIBarButtonSystemItemRefresh
target
:
self
action
:
@selector
(
refresh
:)]
autorelease
];
self
.
navigationItem
.
rightBarButtonItem
.
enabled
=
NO
;
[
self
.
navigationController
.
navigationBar
setTintColor
:[
UIColor
darkGrayColor
]];
self
.
tableView
.
rowHeight
=
70
.
0
f
;
[
self
.
locationManager
startUpdatingLocation
];
}
-
(
void
)
viewDidUnload
{
[
super
viewDidUnload
];
[
self
.
locationManager
stopUpdatingLocation
];
}
#pragma mark - Actions
-
(
void
)
refresh
:
(
id
)
sender
{
self
.
nearbySpots
=
[
NSArray
array
];
[
self
.
tableView
reloadData
];
[[
NSURLCache
sharedURLCache
]
removeAllCachedResponses
];
[[
AFImageCache
sharedImageCache
]
removeAllObjects
];
if
(
self
.
locationManager
.
location
)
{
[
self
loadSpotsForLocation
:
self
.
locationManager
.
location
];
}
}
#pragma mark - CLLocationManagerDelegate
-
(
void
)
locationManager
:
(
CLLocationManager
*
)
manager
didUpdateToLocation
:
(
CLLocation
*
)
newLocation
fromLocation
:
(
CLLocation
*
)
oldLocation
{
[
self
loadSpotsForLocation
:
newLocation
];
}
#pragma mark - UITableViewDataSource
-
(
NSInteger
)
numberOfSectionsInTableView
:
(
UITableView
*
)
tableView
{
return
1
;
}
-
(
NSInteger
)
tableView
:
(
UITableView
*
)
tableView
numberOfRowsInSection
:
(
NSInteger
)
section
{
return
[
self
.
nearbySpots
count
];
}
-
(
UITableViewCell
*
)
tableView
:
(
UITableView
*
)
tableView
cellForRowAtIndexPath
:
(
NSIndexPath
*
)
indexPath
{
static
NSString
*
CellIdentifier
=
@"Cell"
;
SpotTableViewCell
*
cell
=
(
SpotTableViewCell
*
)[
tableView
dequeueReusableCellWithIdentifier
:
CellIdentifier
];
if
(
cell
==
nil
)
{
cell
=
[[[
SpotTableViewCell
alloc
]
initWithStyle
:
UITableViewCellStyleSubtitle
reuseIdentifier
:
CellIdentifier
]
autorelease
];
}
Spot
*
spot
=
[
self
.
nearbySpots
objectAtIndex
:
indexPath
.
row
];
static
TTTLocationFormatter
*
_locationFormatter
=
nil
;
if
(
!
_locationFormatter
)
{
_locationFormatter
=
[[
TTTLocationFormatter
alloc
]
init
];
if
(
!
[[[
NSLocale
currentLocale
]
objectForKey
:
NSLocaleUsesMetricSystem
]
boolValue
])
{
[
_locationFormatter
setUnitSystem
:
TTTImperialSystem
];
}
}
if
(
self
.
locationManager
.
location
)
{
cell
.
detailTextLabel
.
text
=
[
_locationFormatter
stringFromDistanceAndBearingFromLocation
:
self
.
locationManager
.
location
toLocation
:
spot
.
location
];
}
cell
.
spot
=
spot
;
return
cell
;
}
#pragma mark - UITableViewDelegate
-
(
NSString
*
)
tableView
:
(
UITableView
*
)
tableView
titleForHeaderInSection
:
(
NSInteger
)
section
{
if
([
self
tableView
:
tableView
numberOfRowsInSection
:
section
]
>
0
)
{
return
NSLocalizedString
(
@"Nearby Spots"
,
nil
);
}
return
nil
;
}
-
(
void
)
tableView
:
(
UITableView
*
)
tableView
didSelectRowAtIndexPath
:
(
NSIndexPath
*
)
indexPath
{
[
tableView
deselectRowAtIndexPath
:
indexPath
animated
:
YES
];
}
@end
examples/AFNetworking iOS Example/Classes/Models/Spot.h
0 → 100644
View file @
a6910ce3
// Spot.h
//
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@interface
Spot
:
NSObject
{
@private
NSString
*
_name
;
NSString
*
_imageURLString
;
NSNumber
*
_latitude
;
NSNumber
*
_longitude
;
}
@property
(
nonatomic
,
retain
)
NSString
*
name
;
@property
(
nonatomic
,
retain
)
NSString
*
imageURLString
;
@property
(
nonatomic
,
retain
)
NSNumber
*
latitude
;
@property
(
nonatomic
,
retain
)
NSNumber
*
longitude
;
@property
(
readonly
)
CLLocation
*
location
;
-
(
id
)
initWithAttributes
:(
NSDictionary
*
)
attributes
;
+
(
void
)
spotsWithURLString
:(
NSString
*
)
urlString
near
:(
CLLocation
*
)
location
parameters
:(
NSDictionary
*
)
parameters
block
:(
void
(
^
)(
NSArray
*
records
))
block
;
@end
examples/AFNetworking iOS Example/Classes/Models/Spot.m
0 → 100644
View file @
a6910ce3
// Spot.m
//
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import "Spot.h"
#import "AFGowallaAPIClient.h"
@implementation
Spot
@synthesize
name
=
_name
;
@synthesize
imageURLString
=
_imageURLString
;
@synthesize
latitude
=
_latitude
;
@synthesize
longitude
=
_longitude
;
@dynamic
location
;
-
(
id
)
initWithAttributes
:(
NSDictionary
*
)
attributes
{
self
=
[
super
init
];
if
(
!
self
)
{
return
nil
;
}
self
.
name
=
[
attributes
valueForKeyPath
:
@"name"
];
self
.
imageURLString
=
[
attributes
valueForKeyPath
:
@"image_url"
];
self
.
latitude
=
[
attributes
valueForKeyPath
:
@"lat"
];
self
.
longitude
=
[
attributes
valueForKeyPath
:
@"lng"
];
return
self
;
}
-
(
void
)
dealloc
{
[
_name
release
];
[
_imageURLString
release
];
[
_latitude
release
];
[
_longitude
release
];
[
super
dealloc
];
}
-
(
CLLocation
*
)
location
{
return
[[[
CLLocation
alloc
]
initWithLatitude
:[
self
.
latitude
doubleValue
]
longitude
:[
self
.
longitude
doubleValue
]]
autorelease
];
}
+
(
void
)
spotsWithURLString
:
(
NSString
*
)
urlString
near
:
(
CLLocation
*
)
location
parameters
:
(
NSDictionary
*
)
parameters
block
:
(
void
(
^
)(
NSArray
*
records
))
block
{
NSDictionary
*
mutableParameters
=
[
NSMutableDictionary
dictionaryWithDictionary
:
parameters
];
if
(
location
)
{
[
mutableParameters
setValue
:[
NSString
stringWithFormat
:
@"%1.7f"
,
location
.
coordinate
.
latitude
]
forKey
:
@"lat"
];
[
mutableParameters
setValue
:[
NSString
stringWithFormat
:
@"%1.7f"
,
location
.
coordinate
.
longitude
]
forKey
:
@"lng"
];
}
[[
AFGowallaAPIClient
sharedClient
]
getPath
:
urlString
parameters
:
mutableParameters
success
:^
(
id
object
)
{
NSMutableArray
*
mutableRecords
=
[
NSMutableArray
array
];
for
(
NSDictionary
*
attributes
in
[
object
valueForKeyPath
:
@"spots"
])
{
Spot
*
spot
=
[[[
Spot
alloc
]
initWithAttributes
:
attributes
]
autorelease
];
[
mutableRecords
addObject
:
spot
];
}
if
(
block
)
{
block
([
NSArray
arrayWithArray
:
mutableRecords
]);
}
}
failure
:^
(
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
if
(
block
)
{
block
([
NSArray
array
]);
}
}];
}
@end
examples/AFNetworking iOS Example/Classes/Views/SpotTableViewCell.h
0 → 100644
View file @
a6910ce3
// SpotTableViewCell.h
//
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import <UIKit/UIKit.h>
@class
Spot
;
@interface
SpotTableViewCell
:
UITableViewCell
@property
(
nonatomic
,
retain
)
Spot
*
spot
;
@end
examples/AFNetworking iOS Example/Classes/Views/SpotTableViewCell.m
0 → 100644
View file @
a6910ce3
// SpotTableViewCell.m
//
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import "SpotTableViewCell.h"
#import "Spot.h"
#import "UIImageView+AFNetworking.h"
@implementation
SpotTableViewCell
@synthesize
spot
=
_spot
;
-
(
id
)
initWithStyle
:(
UITableViewCellStyle
)
style
reuseIdentifier
:(
NSString
*
)
reuseIdentifier
{
self
=
[
super
initWithStyle
:
style
reuseIdentifier
:
reuseIdentifier
];
if
(
!
self
)
{
return
nil
;
}
self
.
textLabel
.
textColor
=
[
UIColor
darkGrayColor
];
self
.
textLabel
.
numberOfLines
=
2
;
self
.
textLabel
.
backgroundColor
=
self
.
backgroundColor
;
self
.
detailTextLabel
.
textColor
=
[
UIColor
grayColor
];
self
.
detailTextLabel
.
backgroundColor
=
self
.
backgroundColor
;
self
.
imageView
.
backgroundColor
=
self
.
backgroundColor
;
self
.
imageView
.
contentMode
=
UIViewContentModeScaleAspectFit
;
self
.
selectionStyle
=
UITableViewCellSelectionStyleGray
;
return
self
;
}
-
(
void
)
dealloc
{
[
_spot
release
];
[
super
dealloc
];
}
-
(
void
)
setSpot
:
(
Spot
*
)
spot
{
[
self
willChangeValueForKey
:
@"spot"
];
[
_spot
autorelease
];
_spot
=
[
spot
retain
];
[
self
didChangeValueForKey
:
@"spot"
];
[
self
.
imageView
setImageWithURL
:[
NSURL
URLWithString
:
self
.
spot
.
imageURLString
]
placeholderImage
:[
UIImage
imageNamed
:
@"placeholder-stamp.png"
]];
self
.
textLabel
.
text
=
spot
.
name
;
}
#pragma mark - UITableViewCell
-
(
void
)
prepareForReuse
{
[
self
.
imageView
cancelImageRequestOperation
];
self
.
textLabel
.
text
=
nil
;
self
.
detailTextLabel
.
text
=
nil
;
}
#pragma mark - UIView
-
(
void
)
layoutSubviews
{
[
super
layoutSubviews
];
CGRect
imageViewFrame
=
self
.
imageView
.
frame
;
CGRect
textLabelFrame
=
self
.
textLabel
.
frame
;
CGRect
detailTextLabelFrame
=
self
.
detailTextLabel
.
frame
;
imageViewFrame
.
origin
=
CGPointMake
(
10
.
0
f
,
10
.
0
f
);
imageViewFrame
.
size
=
CGSizeMake
(
50
.
0
f
,
50
.
0
f
);
textLabelFrame
.
origin
.
x
=
imageViewFrame
.
size
.
width
+
25
.
0
f
;
detailTextLabelFrame
.
origin
.
x
=
textLabelFrame
.
origin
.
x
;
textLabelFrame
.
size
.
width
=
240
.
0
f
;
detailTextLabelFrame
.
size
.
width
=
textLabelFrame
.
size
.
width
;
self
.
textLabel
.
frame
=
textLabelFrame
;
self
.
detailTextLabel
.
frame
=
detailTextLabelFrame
;
self
.
imageView
.
frame
=
imageViewFrame
;
}
@end
examples/AFNetworking iOS Example/Images/placeholder-stamp.png
0 → 100644
View file @
a6910ce3
3.88 KB
examples/AFNetworking iOS Example/Images/placeholder-stamp@2x.png
0 → 100644
View file @
a6910ce3
5.58 KB
examples/AFNetworking iOS Example/Info.plist
0 → 100644
View file @
a6910ce3
<
?xml
v
e
rsion="
1
.
0
"
e
n
c
o
d
ing="UT
F
-
8
"?
>
<
!
D
O
C
TYP
E
plist
PU
B
LI
C
"-//
A
ppl
e
//
D
T
D
PLIST
1
.
0
//
E
N"
"http://www.
a
ppl
e
.
c
om/
D
T
D
s/Prop
e
rtyList-
1
.
0
.
d
t
d
"
>
<
plist
v
e
rsion="
1
.
0
"
>
<
d
i
c
t
>
<
k
e
y
>
CFBundleDevelopmentRegion
<
/k
e
y
>
<
string
>
en
<
/string
>
<
k
e
y
>
CFBundleDisplayName
<
/k
e
y
>
<
string
>
AFNetworking
<
/string
>
<
k
e
y
>
CFBundleExecutable
<
/k
e
y
>
<
string
>
$
{
EXECUTABLE_NAME
}<
/string
>
<
k
e
y
>
CFBundleIconFile
<
/k
e
y
>
<
string
><
/string
>
<
k
e
y
>
CFBundleIdentifier
<
/k
e
y
>
<
string
>
com.alamofire.$
{
PRODUCT_NAME:rfc1034identifier
}<
/string
>
<
k
e
y
>
CFBundleInfoDictionaryVersion
<
/k
e
y
>
<
string
>
6.0
<
/string
>
<
k
e
y
>
CFBundleName
<
/k
e
y
>
<
string
>
$
{
PRODUCT_NAME
}<
/string
>
<
k
e
y
>
CFBundlePackageType
<
/k
e
y
>
<
string
>
APPL
<
/string
>
<
k
e
y
>
CFBundleShortVersionString
<
/k
e
y
>
<
string
>
1.0
<
/string
>
<
k
e
y
>
CFBundleSignature
<
/k
e
y
>
<
string
>
????
<
/string
>
<
k
e
y
>
CFBundleVersion
<
/k
e
y
>
<
string
>
0.1.0
<
/string
>
<
k
e
y
>
LSRequiresIPhoneOS
<
/k
e
y
>
<
tru
e
/
>
<
k
e
y
>
UISupportedInterfaceOrientations
<
/k
e
y
>
<
a
rr
a
y
>
<
string
>
UIInterfaceOrientationPortrait
<
/string
>
<
/
a
rr
a
y
>
<
/
d
i
c
t
>
<
/plist
>
examples/AFNetworking iOS Example/Podfile
0 → 100644
View file @
a6910ce3
platform
:ios
dependency
'FormatterKit'
dependency
do
|
s
|
s
.
name
=
'AFNetworking'
s
.
version
=
'0.7.0'
s
.
summary
=
'A delightful iOS networking library with NSOperations and block-based callbacks'
s
.
homepage
=
'https://github.com/gowalla/AFNetworking'
s
.
author
=
{
'Gowalla'
=>
'live@gowalla.com'
}
s
.
source
=
{
:git
=>
'https://github.com/gowalla/AFNetworking.git'
,
:tag
=>
'0.7.0'
}
if
config
.
ios?
s
.
source_files
=
'AFNetworking'
# everything
else
s
.
source_files
=
%w{
AFNetworking/AFHTTPRequestOperation.h
AFNetworking/AFJSONRequestOperation.h
AFNetworking/NSData+AFNetworking.h
AFNetworking/NSMutableURLRequest+AFNetworking.h
AFNetworking/NSString+AFNetworking.h
}
end
s
.
clean_paths
=
[
'iOS Example'
,
'Mac Example'
,
'AFNetworking.xcworkspace'
]
s
.
library
=
'z'
s
.
dependency
'JSONKit'
end
examples/AFNetworking iOS Example/Prefix.pch
0 → 100644
View file @
a6910ce3
#import <Availability.h>
#ifndef __IPHONE_3_0
#warning "This project uses features only available in iPhone SDK 3.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
examples/AFNetworking iOS Example/main.m
0 → 100644
View file @
a6910ce3
// main.m
//
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import <UIKit/UIKit.h>
int
main
(
int
argc
,
char
*
argv
[])
{
NSAutoreleasePool
*
pool
=
[[
NSAutoreleasePool
alloc
]
init
];
int
retVal
=
UIApplicationMain
(
argc
,
argv
,
@"UIApplication"
,
@"AppDelegate"
);
[
pool
release
];
return
retVal
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment