how to place url string - iphone

hi i am new to iphone. what i need is i have to place a url as a string eg:http://stackoverflow.com by selecting the string it self open in a web brosewr how can i done this. post some code or link thank u.

Add a textView control onto your NIB file. Put whatever content (you mention 5 lines of text) you want in here. In the properties for this control, under the "Detection" section, click "Links". Then, any URL links in this text will be automatically highlighted in blue, and when your users tap on it they will be taken to that URL in the browser.
Your question could have been a little clearer - I only got what you were after because of your previous comment on puckipedia's answer...

To open A url use (in Objective-C)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:URLHere]];

Related

Paste from the clipboard in iOS

So I have 2 apps. One is a sensors app (built with XCode) that records data (text) with hardware wireless sensors. The other is a checklist/reference manual (built with Titaniam Appcelerator). Using custom URL schemes, they can instantiate each other.
What I am trying to do is paste any text data the sensors app copies to the clipboard into a text field in the reference manual app. I have a UIWebview showing html pages (the checklist) with a text box displayed now. To demo the capability, I have to touch the field and select paste. I was thinking that javascript might work, but all my research poo poo's that idea. Any thoughts about how to grab the text that is on the clipboard and display it programmatically in the reference manual app without having to touch the field and select paste?
Should I even be looking at the clipboard or should I be looking into modifying the custom URL scheme to pass data that way instead?
To get the text from the clipboard:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *string = pasteboard.string;
if (string) {
// Do something
}
For more funcional communication between apps, take a look at URL Schemes.
So, I figured out a way to pass the data in the url with this tutorial. At the bottom it describes how to pass data after you set up the URL id for each app. Hope this helps someone.
Pasting in Swift
Get the pasteboard string with UIPasteboard.generalPasteboard().string.
The string is optional, so it must be unwrapped before being used.
if let pasteboardString = UIPasteboard.generalPasteboard().string {
// use the string, for example:
myTextView.insertText(pasteboardString)
}
Note
The original question is asking for something more complex than this. However, most people come here based on the question title rather than question content, so that I what I am answering here.

How add new window on button click and come back to previous window?

I have an application in which i have a button. I want to open a fb login url in browser and when i login successfully then i want to come back to my application. So problem is that how i fix that?
i use this code for.
-(IBAction)add_account:(id)sender{
switch ( ((UIButton*)sender).tag ){
case 0:
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://graph.facebook.com/oauth/authorize?client_id=xxxxxxxxxxxxx&redirect_uri=http://www.facebook.com/connect/login_success.html&type=user_agent&display=touch&scope=offline_access,publish_stream,read_stream"]];
break;
}
}
}
Thanks in advances...
You need to register an URL scheme for your own app. You can put the URL scheme in your app's project file on the "Info" tab, lower right is an "Add" button which allows to add an URL type. You can now edit that URL type in the list, especially filling out the identifier and more important the URL scheme. Assuming your URL scheme is "myapp":
Every URL starting with myapp:// now will be forwarded to your app. Now you simply have to implement application:openURL:sourceApplication:annotation in your application delegate which will handle all "myapp://" URLs. There you can, for example, extract information from the URL and show a specific view.
The myapp://-URL would of course go as redirect target in your original request.

How to register a custom app opening URL scheme with Xcode 4?

Xcode4 is asking for a huge number of arguments just to make this simple thing possible:
NSString *stringURL = #"twitterriffic://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
What are all these properties for? Why an image? Must I repeat the app identifier here? What role to choose if I want anyone to be able to call this URL to open my app? And what are these Additional url type properties for?
I found no Xcode4-related tutorial how to register such an URL scheme with Xcode 4.
Open "Supporting Files" (folder) on left and click the "YourAppName-Info.plist"
Choose a row like "Bundle creator OS Type Code" and mouse over row and click the (+) symbol
This creates a new row and type "URL types"
Click the arror to left and see Item 0 and you'll rename the value in Item 0 to "URL Schemes" as shown
Then edit the field in Item 0 and type in your prototocol; I typed in "goomzee" as shown
Now if I install this app on my simulator, and open Safari and type "goomzee://" in the address bar it will launch my app.
Yup, this stuff isn't straightforward is it ?
I've outlined the steps required to register a custom URL here:
Custom URLs
But, basically the key to it is setting up a "URL Types" value in your .plist file. Here's what it looks like in XCode 5:
In this example, I've registered the MKB prefix, so now, I can use this new type of URLs in hyperlinks on webpages, and emails (if I read an email in the iPad Mail app):
If a user taps on one of these links, my iPad app will start up, and I can access the full URL string, to extract the other parameters from the URL (eg "DocumentNumber=100")
The only gotcha is that I have yet to work out how to test whether a user has an iPad app installed which can recognise a particular prefix.
If they haven't, and they tap on one of these MKB:// links on their iPad, they'll get an ugly error message:
You can continue to register your custom URL by editing your app's info.plist file (as shown in one of your previous questions). The new editor in Xcode 4 is supposed to be a convenience to make it easier to add the entries - all it is doing is making the same info.plist changes that you would do manually. If you want to use the new editor then you only need to fill in the 'Identifier' and the 'URL Schemes' boxes. You don't need an image, icon or additional URL properties.
The other properties (icon etc) are not well documented but seem to be applicable only on Mac OS X and might be used in the Finder's Get Info dialog to display what types of URL a particular app can open. For example, take a look at the Launch Services Programming Guide.
What you change in that editor is also reflected in your project's info plist file. It takes the form of ProjectName-Info.plist. Hopefully that helps.

PhoneGapHtml5_Problem

Just wanted to ask u how do we link HTML file in PhoneGap Applications.As u know that in when we create PhoneGap application one Html file comes with it i just want to know how it is linked to the application so that i could add more Html files to it and use it ib webview
Thanks all in advance
To use multiple pages you can just link to them as normal. (Remember, use relative links).
It's hower normal to use only 1 page in phonegap application. 1 page that uses hidden divs. Don't really know why, besides the fact symbian only supports 1 page with acces to the device.
Just place your HTML files and other resouces (like images, scripts, etc) inside the "www" folder :) as Erik said, just link them as yoiu normally do. You don't need to edit any Objective-C files (like .m or .h).
Good Luck
PhoneGapDelegate.m is where the phonegap settings are stored. The PhoneGapViewController.m is where the UIWebView is bound to the xib.
Please control click on any web view delegate method placed in App delegate method then in the new class which appears after contrl clicking make following changes...
(NSString*) wwwFolderName { return #"www"; }
(NSString*) startPage { return #"index.html"; }
In these 2 functions i.e wht html file u want to attach in your phone gap u can write the name in start page function as shown above.

How do I know if text contains URL links (UIWebView)

I have some text which might or might not contain web URLs, phone numbers, email links etc. which UIWebView automatically detects as hotspots.
Question: I want to show this text in UIWebView ONLY when there are one or more hotspots, but as plain text if it doesn't. So how can I detect this in code?
Additional Info: JavaScript code below tells how many ... links there are. This does NOT count how many other "link" items there are. For example "Link to www.yle.fi" contains one link according to UIWebView, but zero according to JavaScript:
NSString *s = [webView stringByEvaluatingJavaScriptFromString:
#"document.links.length"];
Still no answer to the question how to ask UIWebView how many links it has found...
You can use several regular expressions and check if the text matches those of URL/phone number/email addresses.
However, if your intention is simply let the user open a link, the UITextView is suffice.
Check the dataDetectorTypes property.