I am currently working on a transit web app to be used with San Diego's Metropolitan Transit System. For iOS, I was planning on using a TabBar with three items, [Home] [Favorites] [Notifications]. [Home] leads to the main page (and to any other pages), [Favorites] is where you can setup your favorite bus/trolley stops.
I was planning on having [Favorites] be where you can setup a notification to be sent to you before a bus arrives at the scheduled times provided by MTS. So for example, if a bus were to come at 10:30 and you set a notification to arrive 5 minutes before to alert you, you would get one at 10:25.
I was wanting to link the accounts with the device tokens, and I read some of the questions on here such as Linking user account to device token for push notifications.
I believe it is possible to somehow link the accounts by sending the device token to the UIWebView when I login.
Hope someone can help me.
EDIT:
Below is the Obj-C code in Home.m
#import "Home.h"
@implementation HomeViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *URL1 = [NSURL URLWithString:@"url"];
NSURLRequest *Request1 = [NSURLRequest requestWithURL:URL1];
[webView1 loadRequest:Request1];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(@"1");
NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
NSString *deviceToken = [defaults objectForKey:@"deviceToken"];
bool tokenIsSent = [defaults boolForKey:@"tokenIsSent"];
NSString *newToken = [defaults stringForKey:@"newToken"];
NSLog(@"2");
NSString *urlString = [NSString stringWithFormat:@"url"];
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSData *usernameData;
NSURLResponse *response;
usernameData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];
NSString *username = [[NSString alloc] initWithData:usernameData encoding:NSUTF8StringEncoding];
NSLog(@"3");
if (deviceToken != nil && tokenIsSent == NO) {
NSLog(@"4");
NSString *urlString = [NSString stringWithFormat:@"url/s=%@&u=%@",newToken, username];
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSData *urlData;
NSURLResponse *response;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];
NSString *info = [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
if([info isEqual: @"success"]){
[defaults setBool:YES forKey:@"tokenIsSent"];
NSLog(@"5");
}else{
[defaults setBool:NO forKey:@"tokenIsSent"];
NSLog(@"6");
}
[defaults synchronize];
} else {
NSLog(@"7");
}
}