HomeStoreForumsWikiiPhone Native AppsiPhone AppsiPhone Apps modmyifone Downloadsmodmyifone Links






Go Back   ModMyiFone.com - iPhone | iPod Touch forums, news, apps, themes. > 3rd Party Apps For iPhone | iPod Touch > iPhone / iPod Touch SDK | Development Discussion
Register FAQ Members List READ THIS Today's Posts Mark Forums Read

iPhone / iPod Touch SDK | Development Discussion SDK questions. A place for iPhone developers to post code snippets, discuss creating iPhone apps, and any other iPhone developing.


iPhone Optimized MMi | Browser Optimized MMi

Get more out of ModMyiFone by joining our free community. By registering you get privileges to download files from our downloads section and you may also post your questions in our forums! It's fast, free, and easy!

Opportunities at MMi | 1.1.4 Unlock|Jailbreak OS X / Win
Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-27-2008, 11:25 PM
celebi23's Avatar
What's Jailbreak?
 
Join Date: Jun 2007
Device + Firmware: iPod Touch 2.0 ;)
Operating System: Mac OS X Leopard v. 10.5.2
Posts: 20
Thanks: 3
Thanked 0 Times in 0 Posts
Tiny question (LaunchMe sample code related)

You know in the "LaunchMe" sample code how you can open Safari & it'll go to apple.com by default? Is there any way to make a UIButton have that function, without all of the messageAlert stuff from LaunchMe? I'm pretty much trying to get a UIButton to open a link to my website in MobileSafari
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #2 (permalink)  
Old 03-28-2008, 06:58 AM
Green Apple
 
Join Date: Dec 2007
Posts: 52
Thanks: 10
Thanked 5 Times in 5 Posts

sure.
you have to use the addTarget:action:forControlEvents method on the button so the button invokes a method when it is clicked.
in that method you just write

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://yoururl.com"]];

and it should work. I never tried it, I'm just guessing from the LaunchMe-Code, but I guess that should work.
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #3 (permalink)  
Old 03-29-2008, 12:24 AM
celebi23's Avatar
What's Jailbreak?
 
Join Date: Jun 2007
Device + Firmware: iPod Touch 2.0 ;)
Operating System: Mac OS X Leopard v. 10.5.2
Posts: 20
Thanks: 3
Thanked 0 Times in 0 Posts

Something like this maybe?

Code:
}
- (void)imagePressed:(UIImage *)imagePressed didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex != -1) {
        // Open Safari only if the user clicked the 'Launch Safari' button, but not if this
        // delegate method is called by UIKit to cancel it. In that case, buttonIndex is -1.
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto:_____________"]];
    }
	[imagePressed release];
}
It produces no error but, doesn't launch the url when the button is clicked

Here's the code for the button mentioned above

Code:
	#pragma mark
	#pragma mark White Button
	#pragma mark
	// create the UIButtons with various background images
	// white button:
	UIImage *buttonBackground = [UIImage imageNamed:@"whiteButton.png"];
	UIImage *buttonBackgroundPressed = [UIImage imageNamed:@"blueButton.png"];
	frame = CGRectMake(xCoord, 300, kStdButtonWidth, kStdButtonHeight);	
	[self addButtonWithTitle:	@"eMail Me"
								selector:@selector(action:)
								frame:frame
								image:buttonBackground
								imagePressed:buttonBackgroundPressed
								darkTextColor:YES];
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #4 (permalink)  
Old 03-29-2008, 03:51 AM
Green Apple
 
Join Date: Dec 2007
Posts: 52
Thanks: 10
Thanked 5 Times in 5 Posts

Quote:
Originally Posted by celebi23 View Post
Something like this maybe?

Code:
}
- (void)imagePressed:(UIImage *)imagePressed didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex != -1) {
        // Open Safari only if the user clicked the 'Launch Safari' button, but not if this
        // delegate method is called by UIKit to cancel it. In that case, buttonIndex is -1.
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto:_____________"]];
    }
	[imagePressed release];
}
It produces no error but, doesn't launch the url when the button is clicked

Here's the code for the button mentioned above

Code:
	#pragma mark
	#pragma mark White Button
	#pragma mark
	// create the UIButtons with various background images
	// white button:
	UIImage *buttonBackground = [UIImage imageNamed:@"whiteButton.png"];
	UIImage *buttonBackgroundPressed = [UIImage imageNamed:@"blueButton.png"];
	frame = CGRectMake(xCoord, 300, kStdButtonWidth, kStdButtonHeight);	
	[self addButtonWithTitle:	@"eMail Me"
								selector:@selector(action:)
								frame:frame
								image:buttonBackground
								imagePressed:buttonBackgroundPressed
								darkTextColor:YES];
well, yeah, that can't really work. I would be surprised if that doesn't produce any errors.
first of all: there is no such thing as a "imagePressed"-method. just because there is a method for UIAlertView-Buttons for that that doesn't mean a method like that exists for everything. there is no imagePressed-method and therefore it is never invoked.
secondly: there is no addButtonWithTitle: method. I mean there is one, but only to add buttons to a UIViewAlert, not to add buttons to anything else. so there is no such thing.
I would heavily advise you to just search the iPhone OS documentation for those things next time, because you find really all the infos you need there (help->xcode documentation or something like that in xcode).
what you have to do: create a UIButton object (for that look for UIButton in the iPhone OS Docs) and then use addTarget:action:forControlEvents on that button (look for that method in the docs).
you can look at the "Hello World" example from apple to see how buttons work and how you notice a click on a button.

regards
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
The Following User Says Thank You to BlackWolf For This Useful Post:
celebi23 (04-03-2008)
  #5 (permalink)  
Old 04-03-2008, 07:00 PM
celebi23's Avatar
What's Jailbreak?
 
Join Date: Jun 2007
Device + Firmware: iPod Touch 2.0 ;)
Operating System: Mac OS X Leopard v. 10.5.2
Posts: 20
Thanks: 3
Thanked 0 Times in 0 Posts

Quote:
Originally Posted by BlackWolf View Post
well, yeah, that can't really work. I would be surprised if that doesn't produce any errors.
first of all: there is no such thing as a "imagePressed"-method. just because there is a method for UIAlertView-Buttons for that that doesn't mean a method like that exists for everything. there is no imagePressed-method and therefore it is never invoked.
secondly: there is no addButtonWithTitle: method. I mean there is one, but only to add buttons to a UIViewAlert, not to add buttons to anything else. so there is no such thing.
I would heavily advise you to just search the iPhone OS documentation for those things next time, because you find really all the infos you need there (help->xcode documentation or something like that in xcode).
what you have to do: create a UIButton object (for that look for UIButton in the iPhone OS Docs) and then use addTarget:action:forControlEvents on that button (look for that method in the docs).
you can look at the "Hello World" example from apple to see how buttons work and how you notice a click on a button.

regards
THANK YOU!!!!!!! I finally got the email button to work 1 major feature down, 1 more major one left to got & then I'm all set for version 1.0 of my app

I do have 1 other question though, I'm using the HelloWorldClassi app as a base & I'm trying to get whatever text I enter to be entered into Google

Code:
//This method is invoked when the Hello button or return key is touched
- (void)hello:(id)sender
{
    [self.textField resignFirstResponder];
    NSString *nameString = self.textField.text;
	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com/search?hl=en&q=",nameString]];
}
But, I keep on getting this one error
Code:
error: too many arguments to function 'URLWithString:'
Any ideas?

Last edited by celebi23 : 04-03-2008 at 07:32 PM.
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #6 (permalink)  
Old 04-04-2008, 11:28 AM
CyberGreg's Avatar
Moderator
 
Join Date: Jul 2007
Device + Firmware: iPhone/Touch 1.1.4/1.1.3
Operating System: OS 10.5.2
Posts: 983
Thanks: 47
Thanked 141 Times in 112 Posts

Quote:
Originally Posted by celebi23 View Post
THANK YOU!!!!!!! I finally got the email button to work 1 major feature down, 1 more major one left to got & then I'm all set for version 1.0 of my app

I do have 1 other question though, I'm using the HelloWorldClassi app as a base & I'm trying to get whatever text I enter to be entered into Google

Code:
//This method is invoked when the Hello button or return key is touched
- (void)hello:(id)sender
{
    [self.textField resignFirstResponder];
    NSString *nameString = self.textField.text;
	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com/search?hl=en&q=",nameString]];
}
But, I keep on getting this one error
Code:
error: too many arguments to function 'URLWithString:'
Any ideas?
Indeed there are too many arguments... notice your "," before nameString. I would suggest you build your complete URL variable and then use that in your "URLWithString" statement.

Something like.... (mind you I have no idea if it works...)
Code:
    NSString *nameString = [[NSString string] stringByAppendingString: @"http://www.google.com/search?hl=en&q=" 
    stringByAppendingString: self.textField.text];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:nameString]];
Here's how my navbar buttons call my help page and my donate page:
Code:
	case 1:	//
		switch( aButton )
		{
			case 0:	{
				NSURL *donateURL = [NSURL URLWithString:DONATE_URL_STRING];
				[self openURL:donateURL];
				[self terminate];
				break; //Donate
			}
			case 1: {
				NSString *helpLink = [NSURL URLWithString:INFO_URL_STRING];
				[self openURL:helpLink];
				[self terminate];
				break; //FAQ
				}
		}
		break;
	}
Where both "*_URL_STRING"'s are constants set in the header file.
__________________
1.1.4 and SDK installed, waiting for iPhone 2.0

---------------iPhone Links, check 'em out-------------------
| iSwitcherAE User Guide | iSwitcher FAQ | Add Installer Source |
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
Reply

  ModMyiFone.com - iPhone | iPod Touch forums, news, apps, themes. > 3rd Party Apps For iPhone | iPod Touch > iPhone / iPod Touch SDK | Development Discussion


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

ModMyMoto.com - ModMyGPhone.com - ModMyiFone.com - Managed Dedicated Servers by SingleHop - iPhone Wallpapers - Contact Us - Link to us - Archive - Privacy Statement - - Top
Copyright © 2007-08 by ModMy, LLC. All rights reserved. You may not copy anything on this site unless you link to the original.
All times are GMT -6. The time now is 10:15 PM. Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5
ModMyiFone.com is an independent publication and has not been authorized, sponsored, or otherwise approved by Apple, Inc or Cisco Systems, Inc. The information contained on this site is for educational purposes only.
Forum skin by poetic_folly