ios 5 how to hook lockscreen notification alert with slider? - iphone

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.

Related

use UIAlertView when camera is running in 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];
}

iPhone SDK: How can you hide an alert box?

I am using the following code to show an alert box:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Info" message:#"My Message" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
Can you tell me how to hide the alert box again when the phone changes orientation?
First you have to save a reference to the alert in your interface.
#interface MyViewController : UIViewController {
UIAlertView *alert;
}
#property (nonatomic, retain) IBOutlet UIAlertView *alert;
when you create the alert you use
self.alert = [[[UIAlertView alloc] initWithTitle:#"Info" message:#"My Message" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] autorelease];
[alert show];
and then you have to add another method didRotateFromInterfaceOrientation:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
[alert dismissWithClickedButtonIndex:[alert cancelButtonIndex] animated:YES];
self.alert = nil;
}

Detecting which UIAlertView was clicked

i need to pop up alert when my application loaded... I called it didfinished launching..
after clicking ok button need to show another alert message i use clickedButtonAtIndex...
Now when I clicked the ok button its calling again and again.. the alertview..
I need to call only once... what to do?
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the tab bar controller's view to the window and display.
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
viewControllersList = [[NSMutableArray alloc] init];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Alow this app to use your GPS location"
delegate:self cancelButtonTitle:#"No" otherButtonTitles:#"Yes", nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex==0) {
NSLog(#"NO");
}
else {
NSLog(#"Yes");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Do you want's to receive Push messages."
delegate:self cancelButtonTitle:#"No" otherButtonTitles:#"Yes", nil];
[alert show];
[alert release];
}
}
#thanks in advance.
set delegate:nil in second alertView
I mean
if (buttonIndex==0) { NSLog(#"NO"); } else {
NSLog(#"Yes");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Do you want's to receive Push messages."
delegate:nil cancelButtonTitle:#"No" otherButtonTitles:#"Yes", nil];
[alert show];
[alert release];
}
Define each UIAlertView and in the delegate look for which Alert to respond to:
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(alert1) {
if (buttonIndex==0) {
NSLog(#"NO");
} else {
NSLog(#"Yes");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Do you want's to receive Push messages." delegate:self cancelButtonTitle:#"No" otherButtonTitles:#"Yes", nil];
[alert show];
[alert release];
}
} else {
/* the second alertview using the same buttonIndex */
}
}
You can also add a tag to your AlertView and te check the tag later on the clickedButtonAtIndex method
UIAlertView* alert = [[UIAlertView alloc]initWithTitle:#"" message:#"All local datawill be erased. Erase local data?" delegate:self cancelButtonTitle:nil otherButtonTitles:#"Erase", #"Cancel",nil];
alert.tag =123; // added the tag so we can prevent other message boxes ok button to mix up
[alert show];
then
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex ==0 && alertView.tag==123){
// Do what ever you wish
}
}
If what you want is to receive the location, just request it and the system will automatically show the message for you. Follow this example:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:tabBarController.view];
// Create a location manager instance to determine if location services are enabled. This manager instance will be
// immediately released afterwards.
CLLocationManager *manager = [[CLLocationManager alloc] init];
if (manager.locationServicesEnabled == NO) {
UIAlertView *servicesDisabledAlert = [[UIAlertView alloc] initWithTitle:#"Location Services Disabled" message:#"You currently have all location services for this device disabled. If you proceed, you will be asked to confirm whether location services should be reenabled." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[servicesDisabledAlert show];
[servicesDisabledAlert release];
}
[manager release];
}
http://developer.apple.com/library/ios/#samplecode/LocateMe/Listings/Classes_AppDelegate_m.html%23//apple_ref/doc/uid/DTS40007801-Classes_AppDelegate_m-DontLinkElementID_4
Same for push notifications.
though u got many implementation solutions already ...but i think better practice would be to assign a tag to each of your AlertView and before detecting the button tapped check the tag of invoking AlertView.Hope this helps.
#Gerard:Though both location manager and push notification service raise system generated messages ,these can be checked off by users not to be shown again.So better HIG complaint method is application generating message whenever push or location manager are required.

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.