Skip to content

Commit

Permalink
PUSH NOTIFICATIONS!!
Browse files Browse the repository at this point in the history
  • Loading branch information
jovhenni19 committed Feb 13, 2014
1 parent 3f4731b commit b32dcd4
Show file tree
Hide file tree
Showing 17 changed files with 191 additions and 31 deletions.
8 changes: 4 additions & 4 deletions AgentBridge.xcodeproj/project.pbxproj
Expand Up @@ -25,7 +25,6 @@
6E5AEF8D184C7C2800FE7B9E /* RequestAccess.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E5AEF8C184C7C2700FE7B9E /* RequestAccess.m */; };
6E5AEF90184C7C2900FE7B9E /* RequestNetwork.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E5AEF8F184C7C2900FE7B9E /* RequestNetwork.m */; };
6E5AEF93184CA8AF00FE7B9E /* Buyer.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E5AEF92184CA8AF00FE7B9E /* Buyer.m */; };
6E63C55B18ABD0810001616B /* libTestFlight.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6E63C55518ABD0810001616B /* libTestFlight.a */; };
6E63C55C18ABD0810001616B /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 6E63C55618ABD0810001616B /* README.md */; };
6E63C55D18ABD0810001616B /* release_notes.md in Resources */ = {isa = PBXBuildFile; fileRef = 6E63C55718ABD0810001616B /* release_notes.md */; };
6E63DF0318A63EA1007931EE /* ABridge_MembershipViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E63DF0218A63EA1007931EE /* ABridge_MembershipViewController.m */; };
Expand All @@ -47,6 +46,7 @@
6EBBD76C1834B1FE00166D63 /* ABridge_ActivityViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EBBD76B1834B1FE00166D63 /* ABridge_ActivityViewController.m */; };
6EBBD7701834B48A00166D63 /* ABridge_ActivityPagesViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EBBD76E1834B48A00166D63 /* ABridge_ActivityPagesViewController.m */; };
6EBBD7751834CA2200166D63 /* ABridge_AgentProfileViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EBBD7741834CA2200166D63 /* ABridge_AgentProfileViewController.m */; };
6EC6A9A618ACD52F00B745A1 /* libTestFlight.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6E63C55518ABD0810001616B /* libTestFlight.a */; };
6EDF11B61845A762001BFC6B /* OpenSans-Bold-webfont.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 6EDF11B51845A762001BFC6B /* OpenSans-Bold-webfont.ttf */; };
6EDF11B91845D5FA001BFC6B /* AgentProfile.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EDF11B81845D5FA001BFC6B /* AgentProfile.m */; };
6EEF583518337E4000C3214E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6EEF583418337E4000C3214E /* Foundation.framework */; };
Expand Down Expand Up @@ -278,7 +278,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
6E63C55B18ABD0810001616B /* libTestFlight.a in Frameworks */,
6EC6A9A618ACD52F00B745A1 /* libTestFlight.a in Frameworks */,
6EFF61501851BBBC00A5A86A /* libz.dylib in Frameworks */,
6EFF614E1851BBAF00A5A86A /* MobileCoreServices.framework in Frameworks */,
6EFF614C1851BBA700A5A86A /* SystemConfiguration.framework in Frameworks */,
Expand Down Expand Up @@ -1014,7 +1014,7 @@
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = "-lxml2";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "AB61BDC2-9539-41BC-9B73-C836E729B625";
PROVISIONING_PROFILE = "DCBDD2CD-63CA-4E1D-93FC-25765A038B3A";
TARGETED_DEVICE_FAMILY = 1;
WRAPPER_EXTENSION = app;
};
Expand Down Expand Up @@ -1044,7 +1044,7 @@
ONLY_ACTIVE_ARCH = NO;
OTHER_LDFLAGS = "-lxml2";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "AB61BDC2-9539-41BC-9B73-C836E729B625";
PROVISIONING_PROFILE = "DCBDD2CD-63CA-4E1D-93FC-25765A038B3A";
TARGETED_DEVICE_FAMILY = 1;
WRAPPER_EXTENSION = app;
};
Expand Down
Binary file not shown.
2 changes: 2 additions & 0 deletions AgentBridge/ABridge_AppDelegate.h
Expand Up @@ -16,6 +16,8 @@
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@property (strong, nonatomic) UIStoryboard* initalStoryboard;
@property (strong, nonatomic) NSString *deviceTokenString;
@property (strong, nonatomic) NSString *tokenId;

- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
Expand Down
22 changes: 21 additions & 1 deletion AgentBridge/ABridge_AppDelegate.m
Expand Up @@ -15,10 +15,18 @@ @implementation ABridge_AppDelegate
@synthesize managedObjectModel = _managedObjectModel;
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
@synthesize initalStoryboard = _initalStoryboard;
@synthesize deviceTokenString = _deviceTokenString;
@synthesize tokenId = _tokenId;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
// UIRemoteNotificationType enabledTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];


UIImage *tabBackground = [[UIImage imageNamed:@"nav_bg.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

Expand All @@ -42,7 +50,19 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

return YES;
}

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog(@"My token is: %@", deviceToken);
NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
self.deviceTokenString = token;
NSLog(@"content---%@", token);
}

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
NSLog(@"Failed to get token, error: %@", error);
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Expand Down
2 changes: 1 addition & 1 deletion AgentBridge/ABridge_FeeCollectionViewController.m
Expand Up @@ -1826,7 +1826,7 @@ - (void) createPaymentPDF {

NSString *grossCommissionSale = [formatter stringFromNumber: [NSNumber numberWithDouble:[self.grossCommission doubleValue]]];

NSString *htmlStringForPDF = [NSString stringWithFormat:HTMLSTRING_PAYMENT, payment_date, self.referral_name, self.loginDetails.user_id, self.profile.broker_name, self.referral_name, self.profile.broker_name,self.textFieldBrokerLicense.text, agent_name, self.textFieldAgentLicense.text, self.textFieldPhoneNumber.text, self.textFieldEmail.text, self.textFieldTaxId.text, self.referral_name, self.client_number, self.client_email, self.client_address, self.client_type, [NSString stringWithFormat:@"%f%%",(self.referral_fee * 100.0f) ], payment_date, grossCommissionSale, [NSString stringWithFormat:@"%f%%",(self.referral_fee * 100.0f) ], referralFeeDetail];
NSString *htmlStringForPDF = [NSString stringWithFormat:HTMLSTRING_PAYMENT, payment_date, self.referral_name, self.loginDetails.user_id, self.profile.broker_name, self.referral_name, self.profile.broker_name,self.textFieldBrokerLicense.text, agent_name, self.textFieldAgentLicense.text, self.textFieldPhoneNumber.text, self.textFieldEmail.text, self.textFieldTaxId.text, self.referral_name, self.client_number, self.client_email, self.client_address, self.client_type, [NSString stringWithFormat:@"%f%%",(self.referral_fee * 100.0f) ], payment_date, grossCommissionSale, [NSString stringWithFormat:@"%f%%",(self.referral_fee * 100.0f) ], referralFeeDetail,self.profile.broker_name, agent_name, self.referral_name, grossCommissionSale,self.profile.broker_name,self.profile.street_address,self.profile.city,self.profile.state_name,self.profile.zip,self.profile.countries_name,agent_name,self.profile.email];

self.payment_id = [NSString stringWithFormat:@"Payment_%@_%@_%@",self.user_id,self.user_id,[date_today stringByReplacingOccurrencesOfString:@"-" withString:@"_"]];

Expand Down
26 changes: 26 additions & 0 deletions AgentBridge/ABridge_LoginViewController.m
Expand Up @@ -11,6 +11,7 @@
#import "LoginDetails.h"
#import "ABridge_AppDelegate.h"
#import "AgentProfile.h"
#import "ASIHTTPRequest.h"

@interface ABridge_LoginViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageViewBackground;
Expand Down Expand Up @@ -309,6 +310,31 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection

if (self.urlConnectionProfile) {
self.labelLoading.text = @"Retrieving Profile.";

NSString *deviceToken = ((ABridge_AppDelegate *)[[UIApplication sharedApplication] delegate]).deviceTokenString;
NSInteger user_id = [self.item.user_id integerValue];


NSString *urlString = [NSString stringWithFormat:@"http://keydiscoveryinc.com/agent_bridge/webservice/register_device.php?user_id=%i&token=%@", user_id, deviceToken];
// NSLog(@"urlString:%@",urlString);
__block NSError *errorData = nil;
__weak ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlString]];
[request setCompletionBlock:^{
// Use when fetching text data
// NSString *responseString = [request responseString];
// Use when fetching binary data
NSData *responseData = [request responseData];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&errorData];
// NSLog(@"json:%@",json);
((ABridge_AppDelegate *)[[UIApplication sharedApplication] delegate]).tokenId = [[[json objectForKey:@"data"] firstObject] objectForKey:@"token_id"];
}];
[request setFailedBlock:^{
NSError *error = [request error];
NSLog(@"error:%@",error);
}];
[request startAsynchronous];


// //NSLog(@"Connection Successful");
}
else {
Expand Down
1 change: 1 addition & 0 deletions AgentBridge/ABridge_MembershipViewController.h
Expand Up @@ -7,6 +7,7 @@
//

#import "ABridge_ParentViewController.h"
#import "ASIHTTPRequest.h"

@interface ABridge_MembershipViewController : ABridge_ParentViewController <UIScrollViewDelegate, UITableViewDataSource>

Expand Down
77 changes: 77 additions & 0 deletions AgentBridge/ABridge_MembershipViewController.m
Expand Up @@ -7,6 +7,7 @@
//

#import "ABridge_MembershipViewController.h"
#import "AgentProfile.h"

@interface ABridge_MembershipViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollViewPlans;
Expand Down Expand Up @@ -89,6 +90,82 @@ - (void)viewDidLoad
self.labelAnnualSave.font = FONT_OPENSANS_REGULAR(FONT_SIZE_REGULAR);
self.buttonMembershipAnnual.titleLabel.font = FONT_OPENSANS_REGULAR(FONT_SIZE_SMALL);


self.labelMonthlyCurrent.hidden = YES;
self.labelQuarterlyCurrent.hidden = YES;
self.labelAnnualCurrent.hidden = YES;

//get profile user_id


NSManagedObjectContext *context = ((ABridge_AppDelegate *)[[UIApplication sharedApplication] delegate]).managedObjectContext;

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"LoginDetails"
inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSError *error = nil;
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];

NSInteger login_user_id = [[[fetchedObjects firstObject] valueForKey:@"user_id"] integerValue];


NSFetchRequest *fetchRequestProfile = [[NSFetchRequest alloc] init];
NSEntityDescription *entityProfile = [NSEntityDescription entityForName:@"AgentProfile"
inManagedObjectContext:context];
[fetchRequestProfile setEntity:entityProfile];

// NSPredicate *predicate = [NSPredicate predicateWithFormat:@"user_id == %i",login_user_id];
//
// [fetchRequestProfile setPredicate:predicate];

NSError *errorProfile = nil;
NSArray *fetchedObjectsProfile = [context executeFetchRequest:fetchRequestProfile error:&errorProfile];

// BOOL found = NO;
AgentProfile *profileFound;

for (AgentProfile *profile in fetchedObjectsProfile) {
if ([profile.user_id integerValue] == login_user_id) {
// found = YES;
profileFound = profile;
break;
}
}

NSInteger profile_user_id = [profileFound.profile_id integerValue];

NSString *parameters = [NSString stringWithFormat:@"?user_id=%i",profile_user_id];

NSMutableString *urlString = [NSMutableString stringWithString:@"http://keydiscoveryinc.com/agent_bridge/webservice/get_membership_fee.php"];
[urlString appendString:parameters];
NSLog(@"url:%@",urlString);
__block NSError *errorData = nil;
__weak ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlString]];
// [self.activityIndicator startAnimating];
// self.activityIndicator.hidden = NO;
[request setCompletionBlock:
^{
NSData *responseData = [request responseData];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&errorData];
NSLog(@"json:%@",json);
if ([[json objectForKey:@"data"] count]) {
self.labelMonthlyName.text = [[[json objectForKey:@"data"] firstObject] objectForKey:@"fee_title"];

}
else {

}

[self.searchDisplayController.searchResultsTableView reloadData];
}];
[request setFailedBlock:^{
NSError *error = [request error];
NSLog(@" error:%@",error);
}];

[request startAsynchronous];

dummy_data_monthly:
{
if (self.arrayBenefitsMonthly == nil) {
Expand Down
24 changes: 23 additions & 1 deletion AgentBridge/ABridge_MenuViewController.m
Expand Up @@ -11,6 +11,7 @@
#import "LoginDetails.h"
#import "AgentProfile.h"
#import "Constants.h"
#import "ASIHTTPRequest.h"

@interface ABridge_MenuViewController ()
@property (weak, nonatomic) IBOutlet UIButton *buttonProfile;
Expand Down Expand Up @@ -322,7 +323,28 @@ - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)butto
[self deleteDataFromEntity:@"RequestNetwork"] &&
[self deleteDataFromEntity:@"RequestAccess"]) {

[((ABridge_AppDelegate *)[[UIApplication sharedApplication] delegate]) resetWindowToInitialView];
NSString *tokenid = ((ABridge_AppDelegate *)[[UIApplication sharedApplication] delegate]).tokenId;


NSString *urlString = [NSString stringWithFormat:@"http://keydiscoveryinc.com/agent_bridge/webservice/delete_device_token.php?token_id=%@", tokenid];

__block NSError *errorData = nil;
__weak ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlString]];
[request setCompletionBlock:^{
// Use when fetching text data
// NSString *responseString = [request responseString];
// Use when fetching binary data
NSData *responseData = [request responseData];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&errorData];
NSLog(@"json:%@",json);
[((ABridge_AppDelegate *)[[UIApplication sharedApplication] delegate]) resetWindowToInitialView];
}];
[request setFailedBlock:^{
NSError *error = [request error];
NSLog(@"error:%@",error);
}];
[request startAsynchronous];

}
else {
//NSLog(@"error on deleting");
Expand Down

0 comments on commit b32dcd4

Please sign in to comment.