use UIAlertView when camera is running in iPhone - iphone

I'm trying to trigger an AlertView when my camera detect a face using OpenCV. I manage to do the face detection and can output an NSLog successfully. But when I tried to trigger the alert view with
NSLog(#"Face Detected");
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"Face Detected" message:#"Do you really want to try again?" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil] autorelease];
[alert addButtonWithTitle:#"Yes"];
[alert show];
[alert release];
I can see the Alert View is kind of triggered as the screen is dimmed but I could never see the alert view came out...
Thanks for helping!

Remove [alert release]. You already called autorelease on it.
Also, you can integrate [alert addButtonWithTitle:#"Yes"]; in the initializer:
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"Face Detected"
message:#"Do you really want to try again?"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil] autorelease];

where are you calling this from ? Main thread or secondary ?
Because UIKit stuff should always been done on main thread.
Code example:
- (void)opencvFaceDetect
{
// stuff before
[self performSelectorOnMainThread: #selector(openAlertView) withObject:nil waitUntilDone:false];
// stuff after
}
and then
- (void)openAlertView
{
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"Face Detected"
message:#"Do you really want to try again?"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil] autorelease];
}

Related

ios 5 how to hook lockscreen notification alert with slider?

All !
What class i have to hook lockscreen notification alert with slider ?
no luck with:
%hook SBAwayController
- (BOOL)activateAlertItem:(id)item
{
%orig;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"SBAwayController" message:#"activateAlertItem" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
return YES;
}
-(void)_pendAlertItem:(id)item
{
%orig;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"SBAwayController" message:#"_pendAlertItem" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
%end
Thanks in advance
I've managed to do this by hooking SBBulletinModalController/SBBulletinBannerController class, addBulletin method
Lockscreen Notification are either shown through push notification or local notification.you can find a lot of tutorial on the same. Here you will find local and push notification programming guide by apple.

Alert view method is not working

In my app i have reset button which delete all the data of tables and database.but before deleting i have to put alert view and ask the question as follows:
- (IBAction)resetData:(id)sender
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Bills Data Entry"
message:#"Are you sure want to reset data?" delegate:nil
cancelButtonTitle:#"No" otherButtonTitles:#"Yes", nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
[self databaseOpen];
NSString *deleteData=[NSString stringWithFormat:#"delete from tbl_Bills"];
[database executeQuery:deleteData];
NSLog(#"inert query: %#",deleteData);
NSLog(#"records deleted");
[table reloadData];
[database close];
// DO STUFF
}
}
This method is not called when i click on yes.
UIAlertView's delegate must not be nil if you want to invoke its delegate method.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Bills Data Entry"
message:#"Are you sure want to reset data?" delegate:self
cancelButtonTitle:#"No" otherButtonTitles:#"Yes", nil];
UIAlertView delegate must be set to self if you want to invoke its delegate method.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Bills Data Entry"
message:#"Are you sure want to reset data?"
delegate:self
cancelButtonTitle:#"No"
otherButtonTitles:#"Yes",nil];
When you are using Delegate method you are supposed to set "delegate: self" instead of nil.
UIAlertView *my_Alert = [[UIAlert alloc] initWithTitle:#"Title of Alert" message:#"Your
Message" delegate:self cancelButtonTitle:#"OK",
otherButtonTitles:nil,nil];

iPhone SDK simple alert message question

char asd='a';
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Are you sure?" message:asd
delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
[alert show];
[alert release];
above code not compiling in iPhone simulator.
Why is that?
:)
You're trying to pass a char where an NSString is expected. Read up on Objective-C and th Cocoa/Cocoa Touch documentation.
To fix your issue, try this:
NSString *asd = #"a";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Are you sure?" message:asd
delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
[alert show];
[alert release];
You don't compile in the iPhone
simulator, you compile on your mac.
Do you get an error message?
The message parameter should be an NSString, not a char?
replace
char asd='a';
With
NSString *asd=#"a";
It should compile after it...

How should I properly format this code?

I've a small issue here. I am using an if statement with UIAlertView and I have two situations, both result in UIAlertViews. However, in one situation, I want to dismiss just the UIAlertView, the other, I want the UIAlertView to be dismissed and view to return to root view.
This code describes is:
if([serverOutput isEqualToString:#"login.true"]){
[Alert dismissWithClickedButtonIndex:0 animated:YES];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
UIAlertView *success = [[UIAlertView alloc] initWithTitle:#"Success" message:#"The transaction was a success!"
delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[success show];
[success release];
} else {
UIAlertView *failure = [[UIAlertView alloc] initWithTitle:#"Failure" message:#"The transaction failed. Contact sales operator!"
delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[failure show];
[failure release];
}
}
-(void)alertView: (UIAlertView *)success clickedButtonAtIndex: (NSInteger)buttonIndex{
switch(buttonIndex) {
case 0: {
[self.navigationController popToRootViewControllerAnimated:YES];
}
}
}
So, in both cases, they follow the above action, but obviously, that's not what I want. Any ideas on what I do here?
You will have to differentiate between the 2 uialertview in your clickedButtonAtIndex: method.
Use the tag property to differentiate.
When you create the alerview assign a tag id to them:
UIAlertView *success = [[UIAlertView alloc] initWithTitle:#"Success" message:#"The transaction was a success!" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
success.tag = 1;
[success show];
Similarly,
failure.tag = 2;
Then you switch on the tag ids
switch(alertView.tag){
case 1: //dismiss alertview
case 2: //dismiss alertview and return to root view
}
You could paste your code in Eclipse, and press ctrl+i.

Iphone popup alert message

I can't find this anywhere. I don't want to have to use the debugger everytime. How do I get print messages on the iphone.
Use the NSLog function:
NSLog(#"Your message here.");
// with parameters:
NSString * myParam = #"Some value";
NSLog(#"myParam:%#", myParam);
The messages get written to the console log. You can view them in the simulator by running Console.app or by switching XCode to the Debugger/Console view (XCode -> Run -> Console)
If you really want to do a popup alert (like the javascript alert() function) you can do :
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Test Message"
message:#"This is a sample"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
// open a alert with an OK and cancel button
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"UIAlertView"
message:#"My message" delegate:self cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
[alert show];
[alert release];
Sample images:
UIAlertView* alert;
alert = [[UIAlertView alloc] initWithTitle:#"Info" message:#"Much more info" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
[alert release];
Look for UIAlertView with either Google or the Xcode Documentation Viewer.