Here is what I am wondering if it is even possible to do. Our app incorporates a changing list of duties. The list is shown in a webview that is edited server side each week. I would like to have the user type in their name on first run ONLY, and have the app detect if the name is found on the html. If it is found, it would pop up a local notification that simply tells them to check the list, as they have a duty to perform that week. Is this possible to do? I was thinking that what they type in is stored as a permanent string (?) and then have enough parsing of the HTML to search for the name. If there is a match, it pops up the notification. Does that sound about right, and how could I store the string, and only prompt the dialog to type in their name on first run?
Here is what I am wondering if it is even possible to do. Our app incorporates a changing list of duties. The list is shown in a webview that is edited server side each week. I would like to have the user type in their name on first run ONLY, and have the app detect if the name is found on the html. If it is found, it would pop up a local notification that simply tells them to check the list, as they have a duty to perform that week. Is this possible to do? I was thinking that what they type in is stored as a permanent string (?) and then have enough parsing of the HTML to search for the name. If there is a match, it pops up the notification. Does that sound about right, and how could I store the string, and only prompt the dialog to type in their name on first run?
See "NSUserDefaults" in the documentation.
As for parsing the HTML - you could either ACTUALLY parse the HTML, or you could just scan for a match, which would be much easier. I'd suggest trying to catch more than just a name, though, unless all your guys have names that can double as strong passwords - maybe name and cell number, or name and UID, etc.
As for parsing the HTML - you could either ACTUALLY parse the HTML, or you could just scan for a match, which would be much easier. I'd suggest trying to catch more than just a name, though, unless all your guys have names that can double as strong passwords - maybe name and cell number, or name and UID, etc.
Thanks, I'll check it out. Regarding catching more than just a name...reason I was wanting to scan for just a name was so the html would be viewable without a lot of other data on it as well. This same HTML doubles for a number of different things on the website we use.
What this does: Finds the string that is the person's name and removes it. Then, it checks if the strings are the same.
If the person's name appeared in the NSString called string, then it is weeded out and the BOOL value returns YES.
Caveats: This logic could return false positives because the name Nat is part of the word National. As long as nothing But names are capitalized, you are good to go. (Make names appear like: NATHANIEL)
What this does: Finds the string that is the person's name and removes it. Then, it checks if the strings are the same.
If the person's name appeared in the NSString called string, then it is weeded out and the BOOL value returns YES.
Caveats: This logic could return false positives because the name Nat is part of the word National. As long as nothing But names are capitalized, you are good to go. (Make names appear like: NATHANIEL)
Thanks! I'll do some reading on the nsuserdefaults and try this out. Been looking through some of the names and other items on the html, and think we should be ok and free from false positives.
Thanks! I'll do some reading on the nsuserdefaults and try this out. Been looking through some of the names and other items on the html, and think we should be ok and free from false positives.
I did some trial and error on all the suggestions and came up with the following in my appdelegate implementation file.
The intent of this is to check if there is already a value entered for firstName key...if a value is detected, it runs checkforservice method I declared...if not, it pulls up the alertview with textfield to enter in their name. Clicking Ok runs this code:
This is to save the textfield text to the nsuser key firstName.
The checkforservice code (to check if the value of the firstName key is contained in text of html code) is this:
Code:
- (void)checkforservice {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *firstName = [defaults objectForKey:@"firstName"];
if ([content rangeOfString:firstName].location != NSNotFound) {
UIAlertView *cancelled = [[UIAlertView alloc] initWithTitle:@"Scheduled To Serve" message:@"You are scheduled to serve this week. Please check the order of worship page to find your assignment." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[cancelled show];
[cancelled release];
}
}
Here is my issue:
I run it the first time, I put in my name. I close the app, close it from multi-tasking, and open it again. This time, it pulls up the alertview that says I am scheduled to serve, because my name was found in the document. I close the app and close it from multi-tasking bar, and then run it again. Now it is asking for my name again. What is causing the key to be deleted that it asks again?
Figured out the problem. Forgot that multiple alertviews would call the same clickedButtonAtIndex, so when I clicked Dismiss for the alert that lets the user know they have something scheduled, it was running the same code as when the user clicked Ok after putting in their name. However, since there is no textField for the other alertview, it would set the nsuserdefault for that key right back to nil.