Trying to add a Vibrate and Sound to my Alert View - iphone

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>

Related

.dylib mobile substrate tweaks not working

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!

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 ?

simple alert view for connection check in a web view

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];

iPhone - a UI component that looks like an Alert box - Beginner

I need to know what this UI component is called ? It looks like an Alert but has textfeilds and buttons in it ?
1.) What is this UIComponent called ?
2.) Is there any video tutorial which shows how to implement this ? (If so link) or any tutorials that discuss the implementation of this
It's UIAlertView
Here is the tutorial to make custom UIAlertView
That is an Android component, there is no equivalent in iOS.
There is the UIAlertView, but you cannot edit text within it.
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIAlertView_Class/UIAlertView/UIAlertView.html#//apple_ref/occ/cl/UIAlertView
If you want to be able to let users edit text in the component, you have to create it from scratch, e.g. create a UIView and add a UITextView to it and some UIButtons and create the functionality to display/dismiss the component yourself.
AlertView
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title"
message:#"Message"
delegate:nil
cancelButtonTitle:#"Cancel"
otherButtonTitles:nil];
[alert show];
[alert release];
The component on iPhone is called a UIAlertView. You can add subviews in it to get text-fields, although this is not recommended by Apple - but you won't get rejected either. In iOS5, there are dedicated UIAlertView types for this. If you are building for iOS5, this is the method you should use.

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.