.dylib mobile substrate tweaks not working - iphone

I was learning about making mobile substrate tweak when i came across a tutorial with a source codes in it. To further understand it, i decided to test it out
The codes:
%hook SBApplicationIcon
-(void)launch
{
NSString *appName = [self displayName];
NSString *message = [NSString stringWithFormat:#"The app %# has been launched, lol", appName, nil];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:appName message:message delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
%orig;
}
%end
I used theos on my IOS phone and made a tweak and paste this code into the "tweak.xm"
I went to "makefile" and added
test_FRAMEWORKS = UIKit
if u ever wonder what is in my test.plist, here is it
com.apple.springboard
Next i went to mobile terminal and did this
su
alpine
cd test
make
Then u copied the .dylib and the "test.plist" file that theos made and pasted it in /Library/MobileSubstrate/DynamicLibraries
After that i respring my device and tried launching an app, but nothing happened. Everything launched normally. Please help me here

After googling for a long time, i finally made it to work
I went to mobile terminal... and login. After that i did this
installsdk3
Then i went to my Makefile and changed it to this
SDKVERSION = 3
include theos/makefiles/common.mk
TWEAK_NAME = test
test_FILES = Tweak.xm
test_FRAMEWORKS = UIKit Foundation
include $(THEOS_MAKE_PATH)/tweak.mk
And i remade the tweak again and it worked!

Related

UIAlertView after completion of NSLog

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 ?

How to view files in iPhone app?

I am building an iPhone app that can save email attachments. I would like to be able to view the files from inside the application as well. I need to be able to view as many kinds of files as possible: .txt, .pdf, .png, .jpeg., .doc, .xls, etc.
The files will reside inside of my application's documents folder. What is the best solution for this? My first thought is to convert my file-paths to URLs and load them in a UIWebView, but I'm not sure if this is the best way, or if it will handle all those file types. Any thoughts?
The way Apple's own Mail app does this is with the QuickLook framework. I'd suggest you do the same. QLPreviewController does all the heavy lifting for you. You can also use UIDocumentInteractionController; this is still using QuickLook behind the scenes to generate the preview.
The UIWebView is the best way to show this kind of file.
Alternatively you can try to read the document in an other app with this code:
UIDocumentInteractionController *interactionController = [[UIDocumentInteractionController interactionControllerWithURL:document.documentURL] retain];
interactionController.delegate = self;
BOOL canOpenDocument = [interactionController presentOpenInMenuFromRect:CGRectMake(365, 200, 300, 400) inView:self.view animated:YES];
if(!canOpenDocument) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"Your phone can't read this kind of file, please install an app from appstore for that" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}

iOS4 (UIAlertView) why this code causes memory leaks?

suppose you create a new iOS app from scratch, with just one single window.
then you put this code in the appDelegate application didFinishLaunching method :
UIAlertView *myAlert = [[UIAlertView alloc]
initWithTitle:#"alert"
message:#"message"
delegate:nil /* same problem with 'delegate:self' */
cancelButtonTitle:nil
otherButtonTitles:#"Ok", nil];
[myAlert show];
[myAlert release];
build and run in simulator 4.1, attach instrument, and...
this causes each time a memory leak.
in simulator 3.1.2 on leopard, no problem at all.
Of course, in a real app, the UIalertView is trigerred by a button, but the result is identical.
What is the problem ?
is UIAlertView buggy until iOS4 ?
Don't check for leaks in a simulator. It doesn't have the same memory model so reports leaks when there aren't any.
Test on a real device and if the leak is still there, report it as a bug to Apple :)

iPhone app crashes while checking internet connectivity

In my iPhone app, I need to detect the internet Connection availability.
So I am referencing some files from "Reachability" project of Apple.
Link is given below:
http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html
I create a new project and implement the code below in viewWillAppear but the app crashes.
I included the Reachability.h, Reachability.m from Apple's demo project.
I also included SystemConfiguration Framework.
app works fine when Internet is Working. But app Crashes when Internet in not Working.
Even I checked the console but there is no notification or error shown in the console.
Reachability *r = [Reachability reachabilityWithHostName:#"www.google.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
if ((internetStatus == ReachableViaWiFi) || (internetStatus == ReachableViaWWAN))
{
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:#"Internet Connection" message:#"Available" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[myAlert show];
[myAlert release];
}
else
{
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:#"No Internet Connection" message:#"This app require an internet connection via WiFi or cellular network to work." delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[myAlert show];
[myAlert release];
}
What could be the reason for crash?
What should I do?
Thanks!!
You're over-releasing the alerts. First, you do autorelease and then additionally release, which is too much. Just remove the two [myAlert release]; and it should work.
Here it may be the case that your code does not work on simulator because of time out. But try running it on device. Also try debugging the code as #greg rightly said. For that credit should go to #greg. Hope this helps. Let me know if it works.
Your problem is elsewhere in your code, as the code you provided along with copying Reachability.[mh] into a fresh Xcode project seems to work without crashing. When your app crashes, it must have some sort of information logged in the console. If there truly is nothing, set a breakpoint in your "startup" methods (viewWillLoad, viewDidLoad, AppDelegate stuff and step through line-by-line until you catch the problem.

Trying to add a Vibrate and Sound to my Alert View

One thing I've learned at engineering school is to always to intense validation of input. I think it's great that with the iPhone SDK you can create a sound and a vibrate option. I would like to put both of these into my Alert View, which shows when the user doesn't fill in a field correctly.
However, I'm getting a ton of errors. Is it not possible to put the vibrate and sound options within an alert view? Here is the code I am using below,
//create vibrate
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
//play sound
SystemSoundID pmph;
id sndpath = [[NSBundle mainBundle]
pathForResource:#"mySound"
ofType:#"wav"
inDirectory:#"/"];
CFURLRef baseURL = (CFURLRef) [[NSURL alloc] initFileURLWithPath:sndpath];
AudioServicesCreateSystemSoundID (baseURL, &pmph);
AudioServicesPlaySystemSound(pmph);
[baseURL release];
//show alert view
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"Age Error"
message:#"Your age must be at least 40 years old and less than 100 years old"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
I have all of the above code in the
- (void)textFieldDidEndEditing:(UITextField *)textField
method.
Here is the errors I get when I try to run it
http://screencast.com/t/Nzc5NDdhMmI
Any help would be greatly appreciated. Not sure what I'm doing wrong since I'm pasting this code directly from another source online.
I've never used the Sound Services, but it looks like you need to import the AudioToolbox framework.
#import <AudioToolbox/AudioToolbox.h>