Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-27-2012, 03:25 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 920
spiderguy84 is on a distinguished road
Default Detect Name in HTML and send Local Notification

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?
__________________
My latest app...i Miss Mommy
spiderguy84 is offline   Reply With Quote
Old 01-27-2012, 04:15 PM   #2 (permalink)
Registered Member
 
Join Date: Jan 2011
Location: South Florida, US
Posts: 357
lgehrig1 is on a distinguished road
Default

Quote:
Originally Posted by spiderguy84 View Post
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.
lgehrig1 is offline   Reply With Quote
Old 01-27-2012, 04:45 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 920
spiderguy84 is on a distinguished road
Default

Quote:
Originally Posted by lgehrig1 View Post
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.
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.
__________________
My latest app...i Miss Mommy
spiderguy84 is offline   Reply With Quote
Old 01-27-2012, 05:06 PM   #4 (permalink)
[[Brain alloc]init];
 
fhsjaagshs's Avatar
 
Join Date: Aug 2011
Location: New Jersey
Age: 15
Posts: 92
fhsjaagshs is on a distinguished road
Default

Code:
- (BOOL)nameAppeared {
NSString *string = [NSString stringWithContentsOfURL:htmlFileUrl];

NSString *stringTwo = [string stringByReplacingOccurencesOfString:name withString@""];

BOOL nameAppeared = [string isEqualToString:stringTwo];

return nameAppeared;
}
Feed in the username.

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)
fhsjaagshs is offline   Reply With Quote
Old 01-27-2012, 09:10 PM   #5 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 920
spiderguy84 is on a distinguished road
Default

Quote:
Originally Posted by fhsjaagshs View Post
Code:
- (BOOL)nameAppeared {
NSString *string = [NSString stringWithContentsOfURL:htmlFileUrl];

NSString *stringTwo = [string stringByReplacingOccurencesOfString:name withString@""];

BOOL nameAppeared = [string isEqualToString:stringTwo];

return nameAppeared;
}
Feed in the username.

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.
__________________
My latest app...i Miss Mommy
spiderguy84 is offline   Reply With Quote
Old 01-28-2012, 12:49 AM   #6 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 920
spiderguy84 is on a distinguished road
Default

Quote:
Originally Posted by spiderguy84 View Post
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.

As part of didfinishlaunchingwithoptions method:
Code:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    NSString *firstName = [defaults objectForKey:@"firstName"];
    if (firstName == nil) {
        UIAlertView *alertforname = [[UIAlertView alloc] initWithTitle:@"Enter Your First & Last Name"     message:@"             "  
                                                       delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];   
        myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)];
        
        CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0, 60);
        [alertforname setTransform:myTransform];
        [myTextField setBackgroundColor:[UIColor whiteColor]];
        [alertforname addSubview:myTextField];
        [alertforname show];
        [alertforname release];
        
    }
    else {
        [self performSelector: @selector(checkforservice) 
                   withObject: nil 
                   afterDelay: 0];

    }
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:
Code:
- (void)alertView:(UIAlertView *)alertforname clickedButtonAtIndex:(NSInteger)buttonIndex {
	
	switch (buttonIndex) {
		case 0:
		{	self.name = [myTextField text];
            NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
            [defaults setObject:name forKey:@"firstName"];
            [defaults synchronize];
		}
            	
	
}
}
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?
__________________
My latest app...i Miss Mommy
spiderguy84 is offline   Reply With Quote
Old 01-28-2012, 10:07 AM   #7 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 920
spiderguy84 is on a distinguished road
Default

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.
__________________
My latest app...i Miss Mommy
spiderguy84 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 411
11 members and 400 guests
Atatator, condor304, FrankWeller, imac74, MAMN84, mraalex, n00b, PowerGoofy, QuantumDoja, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,123
Posts: 402,908
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:57 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0