forked from Simbul/baker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved postAPNSToken function to BakerAPI singleton
- Loading branch information
Showing
6 changed files
with
142 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,7 @@ | |
ABD7D45F1616FC5B008B13B5 /* BakerIssue.m in Sources */ = {isa = PBXBuildFile; fileRef = ABD7D45E1616FC5B008B13B5 /* BakerIssue.m */; }; | ||
ABDC05AF16A4C42A00F6B63D /* JSONStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = ABDC05AE16A4C42A00F6B63D /* JSONStatus.m */; }; | ||
ABDC05B216A4CB3900F6B63D /* ShelfStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = ABDC05B116A4CB3900F6B63D /* ShelfStatus.m */; }; | ||
ABF23B1D1708418E003AA3B0 /* BakerAPI.m in Sources */ = {isa = PBXBuildFile; fileRef = ABF23B1C1708418E003AA3B0 /* BakerAPI.m */; }; | ||
BF3CCCA215D080560087B9CA /* ios-icon-ipad.png in Resources */ = {isa = PBXBuildFile; fileRef = BF3CCC9E15D080560087B9CA /* ios-icon-ipad.png */; }; | ||
BF3CCCA315D080560087B9CA /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = BF3CCC9F15D080560087B9CA /* [email protected] */; }; | ||
BF3CCCA415D080560087B9CA /* ios-icon-iphone.png in Resources */ = {isa = PBXBuildFile; fileRef = BF3CCCA015D080560087B9CA /* ios-icon-iphone.png */; }; | ||
|
@@ -210,6 +211,8 @@ | |
ABDC05AE16A4C42A00F6B63D /* JSONStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSONStatus.m; sourceTree = "<group>"; }; | ||
ABDC05B016A4CB3900F6B63D /* ShelfStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShelfStatus.h; sourceTree = "<group>"; }; | ||
ABDC05B116A4CB3900F6B63D /* ShelfStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShelfStatus.m; sourceTree = "<group>"; }; | ||
ABF23B1B1708418E003AA3B0 /* BakerAPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BakerAPI.h; sourceTree = "<group>"; }; | ||
ABF23B1C1708418E003AA3B0 /* BakerAPI.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BakerAPI.m; sourceTree = "<group>"; }; | ||
BF3CCC9E15D080560087B9CA /* ios-icon-ipad.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "ios-icon-ipad.png"; sourceTree = "<group>"; }; | ||
BF3CCC9F15D080560087B9CA /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; }; | ||
BF3CCCA015D080560087B9CA /* ios-icon-iphone.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "ios-icon-iphone.png"; sourceTree = "<group>"; }; | ||
|
@@ -416,6 +419,8 @@ | |
9F58D84E15D66E870027902C /* UICustomNavigationBar.m */, | ||
9F58D84F15D66E870027902C /* UICustomNavigationController.h */, | ||
9F58D85015D66E870027902C /* UICustomNavigationController.m */, | ||
ABF23B1B1708418E003AA3B0 /* BakerAPI.h */, | ||
ABF23B1C1708418E003AA3B0 /* BakerAPI.m */, | ||
); | ||
path = BakerShelf; | ||
sourceTree = "<group>"; | ||
|
@@ -617,6 +622,7 @@ | |
ABBFD8F216C6614300BA64A4 /* NSString+UUID.m in Sources */, | ||
ABADF3F916C7BAD900F52F3C /* NSURL+Extensions.m in Sources */, | ||
AB67F5BA16EE99B2005A04F6 /* Reachability.m in Sources */, | ||
ABF23B1D1708418E003AA3B0 /* BakerAPI.m in Sources */, | ||
); | ||
runOnlyForDeploymentPostprocessing = 0; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// BakerAPI.h | ||
// Baker | ||
// | ||
// ========================================================================================== | ||
// | ||
// Copyright (c) 2010-2012, Davide Casali, Marco Colombo, Alessandro Morandi | ||
// All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without modification, are | ||
// permitted provided that the following conditions are met: | ||
// | ||
// Redistributions of source code must retain the above copyright notice, this list of | ||
// conditions and the following disclaimer. | ||
// Redistributions in binary form must reproduce the above copyright notice, this list of | ||
// conditions and the following disclaimer in the documentation and/or other materials | ||
// provided with the distribution. | ||
// Neither the name of the Baker Framework nor the names of its contributors may be used to | ||
// endorse or promote products derived from this software without specific prior written | ||
// permission. | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY | ||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT | ||
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface BakerAPI : NSObject | ||
|
||
#pragma mark - Singleton | ||
|
||
+ (BakerAPI *)sharedInstance; | ||
|
||
#pragma mark - APNS | ||
|
||
- (BOOL)postAPNSToken:(NSString *)apnsToken; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// | ||
// BakerAPI.m | ||
// Baker | ||
// | ||
// ========================================================================================== | ||
// | ||
// Copyright (c) 2010-2012, Davide Casali, Marco Colombo, Alessandro Morandi | ||
// All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without modification, are | ||
// permitted provided that the following conditions are met: | ||
// | ||
// Redistributions of source code must retain the above copyright notice, this list of | ||
// conditions and the following disclaimer. | ||
// Redistributions in binary form must reproduce the above copyright notice, this list of | ||
// conditions and the following disclaimer in the documentation and/or other materials | ||
// provided with the distribution. | ||
// Neither the name of the Baker Framework nor the names of its contributors may be used to | ||
// endorse or promote products derived from this software without specific prior written | ||
// permission. | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY | ||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT | ||
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
// | ||
|
||
#import "BakerAPI.h" | ||
#import "Constants.h" | ||
#import "NSMutableURLRequest+WebServiceClient.h" | ||
|
||
#import "Utils.h" | ||
#ifdef BAKER_NEWSSTAND | ||
#import "PurchasesManager.h" | ||
#endif | ||
|
||
@implementation BakerAPI | ||
|
||
#pragma mark - Singleton | ||
|
||
+ (BakerAPI *)sharedInstance { | ||
static dispatch_once_t once; | ||
static BakerAPI *sharedInstance; | ||
dispatch_once(&once, ^{ | ||
sharedInstance = [[self alloc] init]; | ||
}); | ||
return sharedInstance; | ||
} | ||
|
||
#pragma mark - APNS | ||
|
||
- (BOOL)postAPNSToken:(NSString *)apnsToken { | ||
if ([POST_APNS_TOKEN_URL length] > 0) { | ||
NSDictionary *params = [NSDictionary dictionaryWithObject:apnsToken forKey:@"apns_token"]; | ||
NSError *error = nil; | ||
|
||
[self postParams:params toURL:[NSURL URLWithString:POST_APNS_TOKEN_URL] error:&error]; | ||
if (error) { | ||
NSLog(@"Error sending APNS device token %@", error); | ||
return NO; | ||
} | ||
return YES; | ||
} | ||
return NO; | ||
} | ||
|
||
#pragma mark - Helpers | ||
|
||
- (NSData *)postParams:(NSDictionary *)params toURL:(NSURL *)url error:(NSError **)error { | ||
NSMutableDictionary *postParams = [NSMutableDictionary dictionaryWithDictionary:params]; | ||
[postParams setObject:[Utils appID] forKey:@"app_id"]; | ||
|
||
#ifdef BAKER_NEWSSTAND | ||
[postParams setObject:[PurchasesManager UUID] forKey:@"user_id"]; | ||
#endif | ||
|
||
NSURLResponse *response = nil; | ||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:REQUEST_TIMEOUT]; | ||
[request setHTTPMethod:@"POST"]; | ||
[request setFormPostParameters:postParams]; | ||
|
||
return [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:error]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters