I would like to know how to make a basic "Hello, World!" MobileSubstrate tweak.
Getting Started will help you setup the environment for developing. This IPF will help you understand building your tweak/app, and you can look at my github for code examples.
I wrote an answer in another thread which apparently was pretty much liked by some people; have a look at it here.
Still, #EvilPenguin's answer is entirely right, mine just explains a couple of things here and there, but it ends up redirecting you to the same place.
#import <SpringBoard/SpringBoard.h> // for SBScreenFlash
%hook SBAwayLockBar
-(void)unlock // the method you’re hooking
{
%orig;
[[%c(SBScreenFlash) sharedInstance] flash];
}
%end
If you unlock your Device using the Slider it'll screenshot your Screen. Its not a good Tweak, but it was all you asked for.
#import <SpringBoard/SpringBoard.h> // for SBScreenFlash
%hook SBAwayLockBar
-(void)unlock // the method you’re hooking
{
%orig;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Hello World!" message:#"my first Tweak" delegate:nil cancelButtonTitle:#"Cool" otherButtonTitles:nil];
[alert show];
[alert release];
}
%end
This will prompt an alertview to you saying hello world ;)
Have fun
Related
I'm in the process of submitting my app to the App Store, but I read that I must notify the user if the internet connection is down when my app needs it. The Apple page mentioned Reachability as well. Currently, though, I'm using the UIWebView delegate method didFailLoadWithError...
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:#"Error Loading" message:[error localizedDescription] delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[errorAlert show];
}
...and it's working fine. My question is, will my app be rejected for not using Reachability to do this, or is it fine doing what I am currently doing?
Thanks in advance.
No, you're perfectly ok using didFailLoadWithError:.
Reachability class could be used to check if host is up (or internet connection at all) before even trying to load some page. But it is not neccessery, as long as you handle the possible errors - which obviously you do.
EDIT:
It is still a good practice to know wheather you will be able to reach a certain host or not. You could even modify GUI for each case (instead of just reporting an error). But this can always be done in update :)
I am new to iphone..
Actually i wanted to know is it possible to put an UIAlertView after the completion of NSLog as i wanted to check whether the statement really works or not as i cant check NSLog in the iphone.
Please suggest me whether it is possible and how?
NSLog will still work on iPhone..
You can only see it in the console if you have attached the device to your mac..and then use the app.
Anyways.
You can show your AlertView after log like this.( This Nslog is an example..replace with what is your actual log)
NSLog(#" Image Loaded");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Log" message:#"Image Loaded" delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
[alert show];
[alert release];
If the NSLog statement works, it'll show up in the XCode console. So if you debug the app on your phone via XCode, you should see the NSLog. Or did you have something else on your mind ?
dear Stackover community,
Nearly a week I'm struggling around with the fact that I must have a connection check
for my web view so I'm surviving the App review process by Apple :-)
I know that I can use the Reachablity sample but for me as a beginner I would say its not smart to deal with such a code.
I found out that it gets a bit simpler with a simple alert and code like this:
-(void)webview:(UIWebView *)webview didFailLoadWithError:(NSError *)error {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Can't connect. Please check your internet Connection"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show]; }
My problem is that I implemented this code into the .m of my Webviewcontroller and connected the delegate to the Filesowner but the App won't be that nice to me to show me the error message :-)
At the moment I'm using Xcode 4.2.1 with ARC enabled and storyboards.
Would anybody please give me a step by step guide how to get this work?
Its probably the last code I need for my App.
Thanks in advance
The delegate method is:
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;
Note it's "-(void)webView" not "-(void)webview". Just capitalize the "v" in "view" and it will work.
To answer your subsequent question:"now when i stop the loading of the page the error message comes too. Is there another tip ?"
As you can see an NSError is passed to your function. That error contains information about the failure. You can see that information by adding: NSLog(#"Epic fail with error:%#",error); ('Epic' added for dramatic effect). When you log that error you will see a code 'property' listed. Through some experimentation you will see that this code property changes based on the type of error. It seems that this code will equal -1009 for a connection error. All of the possible errors are enumerated here under "URL Loading System Error Codes". Best of all since they are defined in an enumeration you don't have to remember much of that. You can just use:
-(void)webView:(UIWebView *)webview didFailLoadWithError:(NSError *)error {
if (error.code == NSURLErrorNotConnectedToInternet){
NSLog(#"You are not connected");
}
}
TRY ...
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:[error localizedString
]
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
this is the code i have taken form.....
- (void)willPresentAlertView:(UIAlertView *)alertView
{
[[[alertView subviews] objectAtIndex:2] setBackgroundColor:[UIColor colorWithRed:0.5 green:0.0f blue:0.0f alpha:1.0f]];
}
- (void) presentSheet
{
UIAlertView *baseAlert = [[UIAlertView alloc]
initWithTitle:#"Alert" message:#"This alert allows the user to choose between a 'safe' and a 'deadly' choice, indicated by button color.\n\n\n\n"
delegate:self cancelButtonTitle:nil
otherButtonTitles:#"Deadly!", #"Safe", nil];
UITextField *txtFld = [[UITextField alloc] initWithFrame:CGRectMake(60,10,240,31)];
[txtFld setDelegate:self];
[txtFld setBackgroundColor:[UIColor clearColor]];
[baseAlert addSubView:txtFld];
[txtFld release];
[baseAlert show];
}
my question is If it is allowed to change the basic Look and feel of the apple's provided UIControls, because I dont see any reason that apple should not allow this type of customisation.
Alert views have long been standardized to for the same reason things like fire extinguishers and safety signs are standardized i.e. you don't want people to have to puzzle out a new interface while something is going wrong.
In general, it is a bad idea to change something in the interface that has been highly standardized. What benefit will it bring to the end user? Will they think, "Damn, I lost all my data but the alert that told me that sure did look artistic!" More likely, they won't understand that the dialog is actually an alert but rather part of the apps normal functioning.
Having said all that, there is nothing to stop you from creating your own custom view and presenting it modally. That is a far safer and easier route than mucking about under the hood of the Apple API.
I don't know if Apple will reject an app for accessing undocumented subviews, but they certainly recommend against it. In fact, when I was at the iPhone tech talk last week a developer evangelist specifically said not to do this because the implementations will change and your app will break.
Does anyone have any best practices, tips & tricks, or recommendations for how to create modal Alert Views with Cocoa Touch?
I like to think there is a way to make this difficult task trivial or at least easier.
You can use something like this:
void AlertWithMessage(NSString *message)
{
/* open an alert with an OK button */
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Name of the Application"
message:message
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
[alert release];
}
I just use UIAlertView to display modal alerts. What additional functionality are you looking for?
Check out the UICatalog sample code from Apple. It shows the usage of both Alerts and Sheets on the phone.