Is there a list of the codes UIWebView returns in - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error? For example "A server with the specified hostname could not be found." returns -1003. Does Apple, or anyone else, provide a list with all the codes UIWebView returns?
Not specifically UIWebView but there are header files that contain network error codes. CFNetworkErrors.h has the actual numbers and NSURLError.h has the Cocoa symbols. You should be able to find the versions of them that match your SDK by using Spotlight for those file names.
The list of UIWebView related error-codes with description are available in Foundation Constants Reference or CFNetWorkErrors enumeration.
Related
Getting error when i add ZBAR SDK
Multiple methods named ‘count’ found with mismatched result, parameter type or attributed"
If I remove that library then its works perfectly, I have found some solution to type casting by (NSArray *) but I need to do in all file this is long process to do in whole project.
Please check below error image. I have just added library and get this error.
Please suggest
Trust me your only hope is to rebuild the library after renaming the 2 count properties in ZBar to something else (say totalCount).
PS - Been there.
Im having some issues localizing a danish app ive made. (The language, not the pastry)
I have set the CFBundleDevelopmentRegion to da_DK for danish in my info.plist, but the popup appearing for text input is still in english, even on phones running the danish OS.
How in Jobs name can i change this ?
The test device is a non-jailbroken iPhone 4S running iOS 5.1 with Danish as its iOS setting, and a danish itunes account associated.
I do not use .xibs for designs. all interfaces are programmed as viewcontrollers.
In the Xcode's file tree (Project Navigator) select your project. in the right hand pane select your project again. select Info and add your language.
I created a sample project, this is the result:
You can do this directly in the info.plist. Something like this:
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>de</string>
<string>es</string>
<string>ja</string>
</array>
Try adding/setting the "Localized resources can be mixed" flag in Info.plist to YES.
You must localize your app in Danish to make the standard UI elements appear in that language. This is to avoid having a UI with mixed languages.
If you don't use xibs, you'd usually do this by adding a Localizable.strings file to your project. In Xcode's "Add File" dialog, you can use the "Strings File" template (under "Resources") for this.
To actually localize the strings file, open the file inspector (⌘ ⌥ 1) and click the + button in the "Localization" section. You'll end up with the file being displayed as a group in the project navigator, with a sub-entry for each language.
The strings file has the format:
"Label_Text" = "Smørrebrød";
(don't forget the semicolon)
To use localized strings in your code, you can use the NSLocalizedString macro like this:
myLabel.text = NSLocalizedString(#"Label_Text", nil);
(The second parameter is for a comment. This can be useful if you use the genstrings tool to extract localizable strings from your code and give the resulting file to a professional translator.)
If you use the English strings as keys, you can leave the English version of Localizable.strings empty (but don't delete it).
Having a Localizable.strings file in the language that the user has selected will also cause standard UI elements, such as the editing menu, photo picker, and so forth, to appear in that language.
If you can't get it working the official way, as provided by #vikingosegundo, you can do this with some creative engineering (Creative as in, oh my god that is dangerous). I discovered this method when I accidentally overrode [NSBundle localizedStringForKey:value:tableName:].
1) Add a category to NSBundle with the following methods:
#import <objc/runtime.h>
+ (void) load {
Method original, swizzled;
original = class_getInstanceMethod(self, #selector(localizedStringForKey:value:table:));
swizzled = class_getInstanceMethod(self, #selector(swizzled_localizedStringForKey:value:table:));
method_exchangeImplementations(original, swizzled);
}
- (NSString*) swizzled_localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName {
NSLog(#"Key: %#. Value: %#", key, value);
return [self swizzled_localizedStringForKey: key value:value table:tableName];
}
2) Where I simply log the key/value, you want to put an if ([key isEqualToString: xxx] ) block. In there, you want to catch (at least some of) the following key values: Cut, Copy[Menu], Select, Select All, Paste, Delete[Menu], Replace..., Define, Speak, Pause. These are the default values that can appear there.
3) When you have caught the value you can look up in a custom table or use hardcoded values. If you look up in a custom table make sure you have a catch in your swizzled method to avoid infinite looping in your custom table.
NB: Why do you need to swizzle? Because this over-rides all Apple text for you app. You will still want the defaults for all the other strings, so you need to swizzle to get the defaults for the strings you aren't interested in.
Good luck.
Paul
Search if your .xib is localized (you'll find it in the inspector on the right panel) if so go to your Project/Target-Settings press the +-Sign and select "Duplicate English to Danish" or something which means the same (I can't check the right item at the moment)
Btw it's called iPhone 4S.
I have a UIViewController containing a UIWebView which I am using to view various documents. Occasionally a document may attempt to be loaded which is not supported by the UIWebView (e.g. old Excel 2.0 sheet). Currently this causes output in the debug window as follows :
exception: CPMessageException: The file format is invalid.
EXCEPTION CPMessageException: (null)
The webViewDidStartLoad method fires, but neither webViewDidFinishLoad or didFailLoadWithError fires.
The error doesn't crash the app, but I would like to trap this exception to provide my own message for the user. Can anybody suggest how to trap and handle this?
Many thanks,
Jonathan
Unfortunately CPMessageException is part of the private frameworks of Apple, in case of office files, OfficeImport.framework. This is thrown when the framework receives an unusable file.
The reason your application is not crashing is because it is probably being handled in the import code itself. Even setting NSSetUncaughtExceptionHandler will not work (as I have tried in the past).
The best way to go around this would be to use the shouldStartLoadWithRequest delegate method of UIWebView:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
Here you could preemptively stop the file from being loaded into the web view and avoid a clueless blank screen.
(Am not sure if there is a way to read NSLog output on the fly so you could monitor it. But that is probably not a right way to do it!)
Update: Just filed a bug regarding this. Let us see what the Apple Developers have to say on this.
i have a UITableview, in the tableview i'm grabbing a JSON feed. But sometimes it's displaying htmlcharacters like “ instead of “ does anyone know how i can convert this in xcode?
Can i set a encoding for my textlabel?
[[cell textLabel] setText:[item objectForKey:#"title" ]];
When I'm fetching strings from a web server and if they're destined for any User Interface, I usually de-louse (errr, de-percent-escape them) via this "NSString" method:
stringByReplacingPercentEscapesUsingEncoding (documentation linked for you).
This gets rid of the URL encoded pieces of strings.
Now, as to the HTML characters like "“", that requires an additional NSString category to do some work.
And other people have already written this category for you. Take a look at the various answers here and one of them should work well.
I have an AppleScript that I am trying to convert to ScriptingBridge. Since my application is a C++/Obj-C application, ScriptingBridge is much easier to use and quite a bit faster (not to mention I hate dynamically building AppleScripts).
The AppleScript sends a message to Photoshop to open a file. The file parameter is sent as an alias, but ScriptingBridge imports the parameter as an id. I don't know what Obj-C object I should pass in?
I've tried passing an NSURL and an NSString (probably incorrectly :-P), but to no avail. Any suggestions on what I should be passing for the file alias?
The short answer is that you can't open documents in Photoshop with Scripting Bridge.
Apple's docs really spell it out like it is. All classes must have a container, which is a mutable array, that they need to be added to before they can be acted upon, as shown in the generated header...
#interface photoshopCS4Application : SBApplication
- (SBElementArray *) documents;
- (SBElementArray *) fonts;
- (SBElementArray *) notifiers;
... and that is the complete list of top-level containers available to us. The open command requires a photoshopCS4OpenOptions to be generated and populated. Because the API doesn't expose the array to store the newly created photoshopCS4OpenOptions object, we can't use a newly created photoshopCS4OpenOptions object. Therefore we can't make a target document and by extensions can't use the open command in Scripting Bridge. The same can be said of all the commands that require some kind of options object.
The only workaround that I have sorted out is to either open a document with native Applescript called from Cocoa or objc-appscript, and then parse the documents array looking for the one just opened. It's not ideal, but then neither is Scripting Bridge because it requires application developers write their scripting APIs in a very specific way that is not native to the OSA framework.
If your program is such that opening a Photoshop document can be executed outside your AppleScript script/Scripting Bridge code, Cocoa provides a method to open files with a specific application:
[[NSWorkspace sharedWorkspace] openFile:#"/Users/bavarious/Desktop/test.psd" withApplication:#"Adobe Photoshop CS4"];
or, if you want to use the default application that handles that file type, you can drop the application name altogether:
[[NSWorkspace sharedWorkspace] openFile:#"/Users/bavarious/Desktop/test.psd"];
Consider Appscript. http://appscript.sourceforge.net/
Here's the code using that:
APApplication *adobePhotoshopCs4 = [APApplication applicationWithName: #"Adobe Photoshop CS4"];
id result = [[adobePhotoshopCs4 open_] send];
(Note, I'm not a Cocoa programmer - I mainly use Appscript with Python but Appscript comes with ASTranslate which translates Applescript into Python, Ruby or Obj-C and that's the output - but I've found there are subtle mistakes in the past sometimes with the translator)