iPhone - UITextView with html content? - iphone

The UITextView has a method named setContentToHTMLString that displays html inside a UITextView.
But this is a private API and probably gets my app rejected by apple.
Is there any way around this to somehow set the content to an htm string without calling this method directly? or any other way to allow html content in a view that is editable (Keyboard accessible)?

I absolutely loath the Three20 framework. It adds huge bulk to your apps, adds a ton of class categories that you probably don't need, multiplies your compiling time many times on a clean compile, and can cause issues if you accidentally don't set all of the sub-projects settings correctly -- personal horror story, I had an app update in the app store broken on all arm6 devices for 3 weeks after adding Three20 while Apple took their sweet time approving my simple fix.
Anyway, enough bashing on Three20. Here's another option if you want something much more compact that is a simple drop in replacement for UITextView with basic HTML support: http://www.cocoacontrols.com/platforms/ios/controls/bctextview. I don't know if that one supports editing though. This one: http://www.cocoacontrols.com/platforms/ios/controls/egotextview supports rich text editing, but I'm not sure if it's in HTML format. They're both worth a look though to see if you can utilize them for your needs. I would only use Three20 as an absolute last resort, and then still probably wouldn't use it.

The closest thing I know to what you are asking are TTStyledText and TTStyledTextLabel, two classes from the Three20 framework that allows you to treat HTML content. They only support a limited subset of HTML, though, so I don't know if this fit your needs.
If you simply want to display/edit some unformatted text taken from the web, have a look at: +stringWithContentsOfURL:encoding:error:

[UITextView setValue:textString forKey:#"contentToHTMLString"];

Related

Parse BBCode in an iOS app

I'm writing an app for a forum. I can get the posts as HTML but I need to do lots of custom things with the posts as I'm not displaying it in UIWebView but natively as rich text (custom handling of [youtube][/youtube] tags). So I am instead getting the much cleaner BBCode output of the posts.
This tutorial seems to fit my needs well enough, however there are some obvious problems with it. On is that if the user types mis-formed BBC I get back bad HTML. Leaving out the closing [/b] as an example.
I am thinking I may just need to loop through the outputted HTML and track if there is an unclosed tag at the end, however I was hoping that there might be a better way to parse BBCode on the iPhone.
Also, lastly I know that is probably the wrong approach (outlined above) but every stack overflow question I've found on BBCode parsing has said not to reinvent the wheel and just use an existing PHP library. But, of course, this is an iOS app so I can't use any code written in PHP.
The question is, what is the best way to parse BBCode on iOS (and if there isn't a library or example available then is there a tutorial on writing a good quality one yourself)?

Localization issue in iphone

I need to make an application in which the user can toggle between two languages on triggering a click event on a button.
The problem here is that I have seen examples in which, if we want to load our localized nib file, then we need to change the language from the settings options and we can get the proper nib file loaded according to language selected.
I want to do this within my application, meaning I don't want to go to the settings menu and change the language and then reload the application.
I just want the above effect within my application (that is, through a button click event the app should be able to toggle between two languages).
Is it possible, and does Apple allow it?
Nobody here can tell you whether Apple will allow it, but if your app is well designed and there's a good reason for this departure from the usual way of doing things, you've probably got a good shot.
There's nothing to prevent you from loading a nib file localized for a different region. I'd probably avoid trying to use Apple's automatic mechanism, though. Just name your nib files using some pattern and load the appropriate one.
If you want your life to easy, you will take advantage of the Localization built into the operating system. Otherwise, you will have write your own methods to load localized strings or nib files.
There is no reason for Apple to reject an app that shows localized text based on an in-app setting. I work to help developers localize apps and, although I don't suggest this approach, they have done it and I've never heard of a rejection from Apple.
What you won't be able to do is use Apple's built-in tools, which rely on the system settings to determine a user's language and push the text from a Localizable.strings file. But it honestly won't take you too long to implement a similar system yourself using functions akin to gettext.
You essentially need to implement the same basic logic as any localization system:
1) Surround your in-app texts in a function that will display the proper language based on the user's chosen settings
2) Export your source texts (probably English into file
3) Translate the English strings into each language in a separate file
The function you write can follow the lines of gettext, which has examples in many programming languages. If the settings is "French" grab the equivalent string from the French file. If the setting is English, just print the English.
You won't be able to use Apple's tools, but you CAN do it on your own and Apple won't really care as far as I know. However, if you choose to localize into an Apple-supported language, follow this app localization tutorial for iOS using the standard Localizable.strings method.

HTML pages in iPhone apps. Where to start?

I'm looking to create a small reference app. It has a UItabBar and 4 views that each load a UITableView which can be drilled down to display, essentially a page of information and pictures, like a book.
If I want to make the page a little more stylised than just using labels and image views, the common consensus seems to be to create HTML pages and load them in a web view.
Being new to this, please could someone give me some direction on where to even begin with this? As I understand it, I essentially need to develop a web page with a text editor, and then what? Actualy upload online and create a public website? It's a little confusing, and as I'm not a developer, a little disheartening to think I'll now have to learn HTML as well as Obj-C to create a simple app.
I'm sure there are some great tools or alternatives out there and if someone could recommend such avenues I'd be incredibly grateful.
Kind regards,
Ryan
If you want to display HTML pages in a UIWebView you can store them in your bundle and display them from there (so no need to put the pages online). It is best though to stick with the UI controls that Apple provides you with. If you need more customization try subclassing some of the standard controls.
If you customize your UI too much it will just confuse the user and degrade their experience.

Common, reusable iPhone-App configuration screen

I'm writing code that will allow my iphone-app to have a "configuration page".
A grouped, scrolling, UITableView... with cells that contain the needed textFields, switches, sliders, etc.
It is an ENOURMOUS amount of code. Is there an easier way?
Is there a way I could create a simple text-file, contain all my desired design choices and have my (reusable) code build the TableView for me?
Or... can I just do the whole thing quicker/easier in Interface Builder instead of code?
Basically there are two approaches here :
you rely on what Apple gives you and implement a Bundle Settings (basically a dictionary that describes how the settings screen should look like), and then , your settings will be in the "Settings" application of the iPhone.
The drawback here is that what apple provides is quite limited and you won't be able to implement some of the most complicated settings you can see in "standard" (pre-installed) apple application settings.
That's why many developers are switching to "inapp" settings thanks to open source FWK or they reimplement everythingh from scratch but it can be a lot of code as you said.
You reimplement your own UIViewController for settings or you rely on some framework that will provide you the UIViewController to extend from and ease your implementation.
There are 2 good frameworks for that (Jesse cited one of them, but there's another one )
InAppSettings ( http://inscopeapps.com/blog/inappsettings-10/ )
InAppSettingsKit ( http://inappsettingskit.com/ )
A comparison of the two framework can be found here : http://inscopeapps.com/blog/inappsettings-vs-inappsettingskit/
(ok that's from one of the two authors but at least this gives an idea ;)
If you can live with the limitations of the standard application preferences in iPhone, you can actually create this using a settings bundle which only needs a plist and optionally a localized strings file.
You can check out Apple documentations for this:
http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ApplicationSettings/ApplicationSettings.html
Claus
If you're looking for a ready made and reusable solution, you can check
http://www.inappsettingskit.com/
It's open source too, so it's useful as a base.
I never found an easy and efficient way to build complicated table view by using Interface Builder, so I think programming the settings view is more preferable.
If you're talking about using a text file or plist, you may want to mimic the Settings Bundle design of Settings app.
Load the plist data upon the app launch.
I've built something like what you're looking for. Going off Claus's answer as well, it basically just duplicates the interface of the Settings application using the same settings.plist file as the settings app. The only difference is that it's a view controller that you can put inside the app. There's a surprisingly small amount of coding involved, it was just a lot of looking at the settings app to see exactly how things were laid out.

iPhone SDK: Ideas on how to implement a help facility for application

We we wondering what are some ways developers have added a help function to their apps. What are some techniques people have used?
One way we were thinking of is to us UIWebView to display a HTML file with help instructions.
Thoughts appreciated.
I'm using UIWebView right now which pretty much contains all the help in a single page, along with some JQuery things to display popups, etc. But I like the way iCab Mobile (et al.) are doing things which is a sectioned UITableView with each row a separate topic or section within their overall help information (complete with icons...) then in their bundle they have each section in its own html file, organized by localization.
Another thing in my queue for the next release is to provide a dynamic "News" view. The rough idea is as follows... I have on my server a file or CGI where I can place small bits of news I'd like to push out to users. On startup, my app checks for network availability and if present, start a thread to see if anything has changed on the server since last updating the News data. If changes present, post an alert letting user know, and asking if they'd like to read it now. At that point, the latest news is already downloaded and cached, so they can simply read it later if they want, and I won't post anymore alerts until the server file changes again. (And one could add a preference/setting to disable these alerts.)
I'm thinking this would be a good way to let people know that some nasty bug is known and fixed and an update is sitting in the queue, solicit beta testers, promote upcoming features or other apps, etc. I can see where constant alerts everytime I've got something new to promote would get annoying, so having a setting to disable them means the user never has to read them unless they want to. Although some kind of override to warn of recently discovered/fixed bugs seems sensible.
FWIW, the author of Mover+/Mover has just started doing a similar thing, though I think Emanuele is perhaps only showing one Notelet at a time, whereas I envision a bit more of a history (shown in UIWebView) until I decide to age stuff off the bottom of the stack.
I'm using a scroll/page view to show several images containing small notes. Each image then tells the user about the more advanced functions on a specific part of the app.
In my opinion the help should only contain information that isn't a 100% relevant for the use of the application. It should be things the advanced user should use to make more use of the app. It should contain gold for the power users. The "basics" should be so obvious that no help would ever be needed. If that's not the case, I think, you've failed as a developer on the iPhone platform.
(Here's a screen shot from my demo app)
I'm currently creating a fairly complicated app. I'm thinking of doing help as a semi-transparent overlay - help in text form is hard to swallow for users; it's much more helpful to just point at stuff and say "this does that".