I am trying to use a simple implementation of wysihtml5 to be able to perform rich text editing (and store the html directly to be able to save formatting in a standard format).
For this I have implemented wysihtml5 like this
<form>
<textarea id="textarea"></textarea>
</form>
<script src="./wysihtml5/parser_rules/simple.js"></script>
<script src="./wysihtml5/dist/wysihtml5-0.3.0.js"></script>
<script>
var editor = new wysihtml5.Editor("textarea", {
parserRules: wysihtml5ParserRules,
useLineBreaks: false
});
</script>
To be able to manipulate it in iOS, I am using stringByEvaluatingJavaScriptFromString as
- (void) setText:(NSString *)text
{
[self.webView
stringByEvaluatingJavaScriptFromString:[NSString
stringWithFormat:#"editor.setValue(%#)", text]];
}
- (NSString *)getText
{
NSString *text = [self.webView
stringByEvaluatingJavaScriptFromString:#"editor.getValue()"];
return text;
}
However, neither the set works nor the get (always returns an empty string).
Any clues?
- (void)insertHTMLContent:(NSString *)HTMLBody
{
if (HTMLBody) {
NSString *query = [NSString stringWithFormat:#"editor.composer.commands.exec('insertHTML', '%#')", HTMLBody];
[self stringByEvaluatingJavaScriptFromString:query];
}
}
- (NSString *)getContentHtml {
return [self stringByEvaluatingJavaScriptFromString: #"editor.getValue()"];
}
Related
I'm trying to get access token from Google,Yahoo.But I'm getting an error like WACloudAccessControlClient may not respond to setToken.How to declare setToken method here.
-(BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
if(_url)
{
/* make the call re-entrant when we re-load the content ourselves */
if([_url isEqual:[request URL]])
{
return YES;
}
[_url release];
}
_url = [[request URL] retain];
NSString* scheme = [_url scheme];
if([scheme isEqualToString:#"acs"])
{
// parse the JSON URL parameter into a dictionary
NSDictionary* pairs = [self parsePairs:[_url absoluteString]];
if(pairs)
{
WACloudAccessToken* accessToken;
accessToken = [[WACloudAccessToken alloc] initWithDictionary:pairs];
[WACloudAccessControlClient setToken:accessToken];
[self dismissModalViewControllerAnimated:YES];
}
return NO;
}
[NSURLConnection connectionWithRequest:request delegate:self];
return NO;
}
Any ideas? Thanks in advance.
You need to pass the message to an object not a class name so first get a reference to an object.
I'm not sure what is your usecase, just look at WACloudAccessControlClient api it will have some init or ...with... methods to create or get a reference to an object of the class.
This:
[WACloudAccessControlClient setToken:accessToken];
Should be something like (the init... method is made up, please replace with actual one):
[[WACloudAccessControlClient initSomethingSomehow] setToken:accessToken];
Are you after something like this?:
[[WACloudAccessControlClient accessControlClientForNamespace:#“namespace-name”
realm:#“realm-name”]
setToken:accessToken];
Edit:
Have a look at this example of how to interact with wa toolkit for iOS I've just skimmed through but it seems to have answers you are looking for.
I am receiving a description text in HTML format, and I am loading it in a webview, if a link clicked in the description so I load it in separate view controller. But shouldStartLoadWithRequest giving a some appended link. here is my code
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if(navigationType == UIWebViewNavigationTypeLinkClicked) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
WebsiteViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"WebsiteViewController"];
vc.url = request.URL.absoluteString;
NSLog(#"link is : %#", [[request URL] absoluteString]);
[self.navigationController pushViewController:vc animated:YES];
return false;
}
return true;
}
it prints this
link is : applewebdata://038EEEBF-A4C9-4C7D-8FB5-32056714B855/www.yahoo.com
and I am loading it like this
[webViewDescription loadHTMLString:description baseURL:nil];
As you are using loadHTMLString and you are setting baseURL to nil therefore applewebdata URI scheme is used by iOS instead of the “http” in URIs used for accessing internal resources on the device. You could try setting the baseURL
I had a similar issue. In practice, setting the baseURL to 'http://' or something like that wasn't working for me either. I also only saw the applewebdata scheme about 50% of the time, the other 50% of the time I saw the correct scheme I was expecting.
To resolve this, I ended up intercepting -webView:shouldStartLoadWithRequest:navigationType: callbacks and using a regular expression to strip out Apple's applewebdata scheme. Here's what it ended up looking like
// Scheme used to intercept UIWebView callbacks
static NSString *bridgeScheme = #"myCoolScheme";
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
BOOL shouldStartLoad = YES;
NSURL *requestURL = request.URL;
// Strip out applewebdata://<UUID> prefix applied when HTML is loaded locally
if ([requestURL.scheme isEqualToString:#"applewebdata"]) {
NSString *requestURLString = requestURL.absoluteString;
NSString *trimmedRequestURLString = [requestURLString stringByReplacingOccurrencesOfString:#"^(?:applewebdata://[0-9A-Z-]*/?)" withString:#"" options:NSRegularExpressionSearch range:NSMakeRange(0, requestURLString.length)];
if (trimmedRequestURLString.length > 0) {
requestURL = [NSURL URLWithString:trimmedRequestURLString];
}
}
if ([requestURL.scheme isEqualToString:bridgeScheme]) {
// Do your thing
shouldStartLoad = NO;
}
return shouldStartLoad;
}
I am teaching myself how to program an iPhone app by looking at code examples from various sources online, so it is fair to say that I do not understand the language (yet).
I am have successfully built a UIWebView browser app that goes to a login page. However, I am trying to take it one step further by having the
Following Byron's code on his own stack overflow question, I have tried to follow in his footsteps.
Is it possible for a UIWebView to save and autofill previously entered form values (e.g., username & password)?
However, when the following line of code is live in the app, the browser will only load a blank page.
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType; {
I really appreciate any assistance to help get me back on the right track. Thank you very much,
Below is my entire code:
#import "ViewController.h"
// 6/13/2012 added to cache username and password
#import
#import "SFHFKeychainUtils.h"
// -----
#interface ViewController ()
#end
#implementation ViewController
#synthesize webView;
#synthesize spinner;
-(IBAction)goBack:(id)sender{
if ([webView canGoBack]) {
[webView goBack];
}
}
-(IBAction)goForward:(id)sender{
if ([webView canGoForward]){
[webView goForward];
}
}
- (void)viewDidLoad
{
NSURL *url = [NSURL URLWithString:#"http://xxxxxx.com/weblink/hh_login.html"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
// 6/13/2012 added to cache username and password
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType; {
//save form data
if(navigationType == UIWebViewNavigationTypeFormSubmitted) {
//grab the data from the page
NSString *username = [self.webView stringByEvaluatingJavaScriptFromString: #"document.myForm.username.value"];
NSString *password = [self.webView stringByEvaluatingJavaScriptFromString: #"document.myForm.password.value"];
//store values locally
[[NSUserDefaults standardUserDefaults] setObject:username forKey:#"username"];
[SFHFKeychainUtils storeUsername:username andPassword:password forServiceName:#"MyService" updateExisting:YES error:nil];
}
}
// -----
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
[spinner startAnimating];
}
//- (void)webViewDidFinishLoad:(UIWebView *)webView {
// [spinner stopAnimating];
//}
// 6/13/2012 added to cache username and password
- (void)webViewDidFinishLoad:(UIWebView *)webView{
[spinner stopAnimating];
//verify view is on the login page of the site (simplified)
NSURL *requestURL = [self.webView.request URL];
if ([requestURL.host isEqualToString:#"http://xxxxxx.com/weblink/hh_login.html"]) {
//check for stored login credentials
NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:#"username"];
if (username.length != 0 ) {
//create js strings
NSString *loadUsernameJS = [NSString stringWithFormat:#"document.myForm.username.value ='%#'", username];
NSString *password = [SFHFKeychainUtils getPasswordForUsername: username andServiceName:#"MyService" error:nil];
if (password.length == 0 ) password = #"";
NSString *loadPasswordJS = [NSString stringWithFormat:#"document.myForm.password.value ='%#'", password];
//autofill the form
[self.webView stringByEvaluatingJavaScriptFromString: loadUsernameJS];
[self.webView stringByEvaluatingJavaScriptFromString: loadPasswordJS];
}
}
}
// -----
#end
TRY BELOW ONE
You need to fill the credential when webview has loaded .
below is the delegate method of UIWebView called when the WebView has loaded.At this time pass the credential not as were passing before loading the UIWebView which is not correct.
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
if(!isLoggedIn){//just load only onetime.
//pass the login Credintails into textfield of WebView.
NSString* userId = #"userName" //here just replace that string to the username
NSString* password = #"password";//here just replace that string to the password
if(userId != nil && password != nil ){
NSString* jScriptString1 = [NSString stringWithFormat:#"document.getElementById('username').value='%#'", userId];
//username is the id for username field in Login form
NSString* jScriptString2 = [NSString stringWithFormat:#"document.getElementById('password').value='%#'", password];
//here password is the id for password field in Login Form
//Now Call The Javascript for entring these Credential in login Form
[webView stringByEvaluatingJavaScriptFromString:jScriptString1];
[webView stringByEvaluatingJavaScriptFromString:jScriptString2];
//Further if you want to submit login Form Automatically the you may use below line
[webView stringByEvaluatingJavaScriptFromString:#"document.forms['login_form'].submit();"];
// here 'login_form' is the id name of LoginForm
}
isLoggedIn=TRUE;
}
}
It'll really help you.
In my app I download an HTML file from a server and check if an image is currently on the website and set a status to a label when the image was found. All works great but I like to
show the user a Loading status label while the app is downloading the file. It works with static text but how can I show running points after the Loading text? I like to see: Loading > Loading. > Loading.. > Loading... > Loading > and so on (I don't need an exact progress bar)
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
platzStatusLabel.text = #"Loading";
if (myConnection == nil) {
myData = [NSMutableData new];
NSString *urlString = [NSString stringWithFormat:#"http://www.myURL.com"];
myConnection =[NSURLConnection connectionWithRequest:
[NSURLRequest requestWithURL:
[NSURL URLWithString:urlString]]
delegate:self];
}
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *stringToLookup = [[NSString alloc]initWithData:myData encoding:NSASCIIStringEncoding];
if ([stringToLookup rangeOfString:#"image_green"].location != NSNotFound){
platzStatusLabel.text = #"Course is open.";
} else {
platzStatusLabel.text = #"Course is closed.";
}
[self initializeVariablesAgain];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[myData appendData:data];
}
- (void) initializeVariablesAgain {
myData = nil;
myConnection = nil;
}
Why not start a UIActivityIndicator (this circly thing that highlights) upon creation of the request and stop it in didFinishLoading?
Or start and stop an NSTimer that iterates through your several strings in the same fashion.
Lastly, you could iterate through your different strings in didReceiveData.
Cheers
Update your counter (file size downloaded updates) in
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
eg.
[myData appendData:data];
self.myCountInBytesOfDownloadProgress = [myData length];
I am using this API to create an online image gallery for my application but the problem is I need create a dynamic gallery this code from sample code shows just a few images from flickr, I need show images from a URL here is the code:
For example: www.mysite.com/gallery
And on this URL there are many photos!
- (id)init {
self = [super init];
if (self) {
// Create a 2-dimensional array. First element of
// the sub-array is the full size image URL and
// the second element is the thumbnail URL.
images_ = [[NSArray alloc] initWithObjects:
[NSArray arrayWithObjects:#"http://farm5.static.flickr.com/4001/4439826859_19ba9a6cfa_o.jpg", #"http://farm5.static.flickr.com/4001/4439826859_4215c01a16_s.jpg", nil],
[NSArray arrayWithObjects:#"http://farm4.static.flickr.com/3427/3192205971_0f494a3da2_o.jpg", #"http://http://farm4.static.flickr.com/3427/3192205971_0f494a3da2_o.jpg" , nil];
}
return self;
}
#pragma mark -
#pragma mark KTPhotoBrowserDataSource
- (NSInteger)numberOfPhotos {
NSInteger count = [images_ count];
return count;
}
- (void)imageAtIndex:(NSInteger)index photoView:(KTPhotoView *)photoView {
NSArray *imageUrls = [images_ objectAtIndex:index];
NSString *url = [imageUrls objectAtIndex:FULL_SIZE_INDEX];
[photoView setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:#"photoDefault.png"]];
}
- (void)thumbImageAtIndex:(NSInteger)index thumbView:(KTThumbView *)thumbView {
NSArray *imageUrls = [images_ objectAtIndex:index];
NSString *url = [imageUrls objectAtIndex:THUMBNAIL_INDEX];
[thumbView setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:#"photoDefault.png"]];
}
Does the gallery website return json or xml? If it does not then you would need to read HTML returned from the gallery website and retrieve image tags. You can use http://github.com/topfunky/hpple/tree/master or http://github.com/zootreeves/Objective-C-HMTL-Parser to parse HTML. For simple HTML this approach should work.
If the HTML is complex then use YQL to scrape the gallery website and convert to JSON.