URL link in Rich Text inside of Webview - iphone

I have been trying to figure this one out for a while but I just can't seem to find an answer. I have an app that I am working on that contains rich text within a WebView, I would like to be able to add a hyperlink within that but I just don't know how.
This is my code:
+(NSArray*)getSampleData
{
NSString* content0 = #"<b><u>For Printer Models:</b></u> IJ2040, 3000, 3160. </p><p>Cable Part Number: CD-023A. </p><p>Connector: RJ12. </p><p>Interface Type: <ul><li><p>12 Volt MultiPRO II: 420</li></p><li><p>12/24 Volt MultiPRO III: 520.</ul></p><p>Manufacturer Website: www.addmaster.com";
}
BusinessService* service0 = [[BusinessService alloc] initWithCaption:#"Addmaster" andImage:[UIImage imageNamed:#"interface.jpg"] andWebContentTitle:#"Connectors for Addmaster" andWebContent:content0 andWebContentImage:[UIImage imageNamed:#"interface.jpg"]];
Now I would like to be able to link directly from the webview to www.addmaster.com so that anyone reading that, can just click on the link to open up safari. Please let me know if it is possible. Thank you very much for your help.

Related

Scraping source view image link with SwiftSoup

I'm trying to grab faveIcon image from a website using SwiftSoup
if rel == "icon", try element.attr("type") == "image/x-icon", element.hasAttr("href") {
favIconUrl = try element.absUrl("href")
}
The issue is, in href, there is no any direct url, and it looks like an hyperlink (not so expert on HTML), it's href="/favicon.ico" , which favicon.ico is clickable and it will open the url. My question is, how I can access to the link inside the favicon.ico? Your help would be appreciated.
Many thanks

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.

detecting URL and format it in UITextField

I would like to be able to format a URL in my UITextField nicely. So say the text of the UITextField is
textField.text = #"Hi this is a page for my website http://www.mywebsite.com";
I would like it to automatically underline this mark it as a hyperlink and when a user taps on the link it opens up the site. This is similar to any twitter client that you have out there (tweetdeck, tweetbot, etc). How do I do this the easy way?
You can use a UITextView instead and set the dataDetectorTypes property to the types of links you want to be able to handle.
hey this is really simple, you can set the UITextFiled to detect Links, like so:
myTextView.dataDetectorTypes = UIDataDetectorTypeAll
check out my tutorial on this at my site for more info
http://www.sdkboy.com

how to place url string

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

iPhone Book Application

What im tyring to create is an application the utilizes book features like when the user drags a touch or just touches the right screen the page turns, the book im trying to create has atleats 300 pages. What i need is a starting point on how to access the text data and display it on a view. When the user changes the page the next set of text is accesed and displayed. How would i be able to model a book with so many pages?
any help is appreciated
PS: ive tried looking for simple tutorials but no luck
If you have your text data in a .txt file then you can extract it from there first of all. This post gives info on how you can do that.
Then every time you flick the page just load in an appropriate substring from the entire text. This would be best in an uneditable UITextView. It could look something like this:
int maxCharPerPage = 200;
int lastCharPreviousPage = 1000;
NSRange thisPageRange = NSMakeRange(lastCharPreviousPage+1, lastCharPreviousPage+1+maxCharPerPage);
NSString *thisPageText = [entireBookText substringWithRange:thisPageRange];
textView.text = thisPageText;
Or you could use a UILabel on top of a view but this approach isn't really what UILabel is designed for.