Can I use UIDocument in a Mac OSX app? - ios

I would like to share a common document format between iOS and OSX. Note that this is not an MDI application; there will ever be one document to save/load. NSDocument style user driven management (e.g.. Save, Save As, Open etc.) is not required.
The biggest challenge is there seems to be no common document encoding format naturally compatible with OSX and IOS (yet). According to Document-Based Application Programming Guide for iOS, it looks like encoding/decoding conversion is required between NSDocument and UIDocument derived classes. I wish there is a universal serialization mechanism compatible with all devices across Apple ecosystem. Any thoughts, ideas, tips are appreciated in this regard.
Can I use a UIDocument derived class in my mac osx application and the document becomes compatible with IOS?

No, you can't use or subclass UIDocument in a Cocoa application because UIDocument doesn't exist in Cocoa.
In both NSDocument and UIDocument, you determine the format that you will use. So, just implement them both to use the same format for the output and the input.
It wouldn't be too hard to use the preprocessor to set up a file-pair that implements a subclass of NSDocument when building for the Mac and UIDocument when building for iOS. This would prevent you from having mismatched serialization and deserialization implementations, since you'd have only one copy of each and be using it on both platforms.

Peter's answer above is correct, but I have a suggestion that does not involve the C pre-processor (not available in Swift) that is a bit more Cocoa-like.
Watch WWDC 2014 session 233 to set up your iOS and Mac apps in a single Project as separate targets, then use Categories on your document class to implement the common functionality:
CommonFunctions.h
#interface AppDocument (CommonFunctions)
- (void)function;
#end
-
CommonFunctions.m
#implementation AppDocument (CommonFunctions)
- (void) function {
/// stuff here
}
#end
Your AppDocument class would have 2 different classes inheriting from UI/NSDocument as necessary for each platform/target, and each target would pull in the categories from a common place.

Related

MITM attack reported on deprecated NSURLConnectionDelegate

I have an Objective-C project whose .ipa was tested with this tool online: https://www.immuniweb.com/mobile
It reports that my app has a high risk security issue, pointing to the canAuthenticateAgainstProtectionSpace in the NSURLConnectionDelegate protocol.
This method has been deprecated by iOS after 8.0 version. My app is not using it directly anywhere and I suppose this is not used by apple also even indirectly, since it is deprecated.
I tried a sample ipa (new project with nothing in it) with Objective-C project and the same issue came for that as well. But it did not come for a sample ipa which supported Swift. Even if this is just a warning, is there a way to fix other than just supporting Swift language only?
The tool has detected that the .h file that defines the NSURLConnectionDelegate protocol declares the canAuthenticateAgainstProtectionSpace function. This is, of course, to be expected.
It would make more sense for the tool to report implementations of the method, not simply declarations of it
Since you haven’t implemented this method you don’t need to worry about flaws in your implementation.
As for getting rid of the issue...Don’t use the tool? It doesn’t seem very good based on this.
Is there an option to tell it not to scan .h files?
TBH it seems like a bug in the tool if not any of your Libraries or Frameworks internally uses that.
In your test for the sample Objective C project it's reported as bug however for a sample swift project it's not reported Hence I guess it's more of bug from the tool side.
I would suggest you to report this issue to them.Hopefully they will get you back with some suggestions.
or
you can try some other pen-testing tools as well.

How to wrap existing iOS code in a new Appcelerator module?

This seems like a basic request, but I can't find the answer to it anywhere. I want to wrap some existing iOS code that I wrote, in a Appcelerator module. That's it. Important points:
I am NOT wrapping a pre-existing 3rd party iOS SDK.
I wrote the iOS code being wrapped.
Code is verified as working within xcode.
There are no .a files. There are 2x .h files and 2x .m files though.
There are no UI elements in the iOS code as it is only designed to connect the native bluetooth hardware to the app.
I have created a generic appcelerator iOS module project, built it, and successfully called the generic ID function within my app.
I cannot figure out how to successfully edit the generic module so that it utilizes my code. Every attempt results in it refusing to compile, and it's maddening.
I do not have access to Hyperloop.
Once I can successfully build the wrapped module, I would call an initialization function which triggers a native bluetooth hardware search. Once connected, there are functions within the module to send commands to the hardware and receive data back. This is the official documentation I've followed so far:
http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Module_Quick_Start
That helped me build the blank module, include it in the app, and ensure that it worked by calling the built in test property. From there it stops short of actually telling me what I need to know. These are the closest things I've found so far, while still not being what I need:
http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Module_Project-section-43288810_iOSModuleProject-AddaThird-PartyFramework
appcelerator module for existing ios project sdk
Heck, I still don't even know if I can do this within studio or if I have to edit the generic module in Xcode. Help! :) Many thanks in advance.
so first of all, this is not best practice and will cause possible problems in the future when the SDK changes and your module still relies on outdated core API's.
Regarding your question, you could either create a new component that subclasses the existing class, e.g.
class TiMyModuleListViewProxy : TiUiListViewProxy {
}
and call it with
var myList = MyModule.createListView();
or you write a category to extend the existing API with your own logic, e.g.
#interface TiUIListViewProxy (MyListView)
- (void)setSomethingElse:(id)value;
#end
#implementation TiUIListViewProxy (MyListView)
- (void)setSomethingElse:(id)value
{
// Set the value of "somethingElse" now
}
#end
I would prefer the second option since it matches a better Objective-C code-style, but please still be aware of the possible core-changes that might effect your implementation in the feature. Thanks!

What is the core Difference between Runtime Headers and just "Headers"?

I'm in process of making a new iOS tweak. I grabbed iOS Headers https://github.com/MP0w/iOS-Headers.
Later on I figured out another repository on Github named iOS Runtime Headers https://github.com/nst/iOS-Runtime-Headers
Now i'm confused. What is the difference between these two?
There are 3 main sources for headers: from the developer of the code, from class-dump, and from a runtime header dumping tool.
Apple or SDK developers will release a header file that includes the public interface they intend other developers to use. It might not include some methods/variable declarations they don't want you to see. UIView.h from Apple's SDK would be a great example of something they're hiding certain info from.
Just because they didn't include those methods in the header file, doesn't mean that instances of those classes can't respond to them. This is where a tool like class-dump comes in, which looks through the compiled Mach-O files to determine which methods/ivars the class contains, and generate a header according to that.
Entirely new classes, methods, and ivars can be added to removed during runtime, using Objective-C's runtime features. Things like categories that get loaded from other SDKs/object files won't appear in a class-dump of the original class either. For these reasons, runtime dumping tools can see what instances of these classes can actually respond to during runtime.
Each set of headers can be useful in determining the intended and unintended uses for a class, knowing the differences can help you get a clearer picture of whatever you're reverse engineering.
It's hard to say what the differences are. They are both sets of headers generated with runtime introspection. The first one says it's headers both public and private.
Just so everybody understands, both links point to sets of headers that give you access to private OS APIs. Using these will get you rejected from the app store. They're only really useful for developing apps for the developer's personal use, or for jailbroken development.

How can I find out which Cocoa classes and APIs are portable across MacOSX and IOS?

There are a number of useful business logic classes which seem to exist in both iOS and MacOSX (for example, NSMutableDictionary).
However as far as I can see the developer documentation does not indicate which they are - you're either using the Mac developer docs (in which case it will tell which version of OSX the API appeared in), or the iOS docs (in which case ditto for iOS).
Is there any documentation set (or alternative easy way) to find out which classes exist in both - i.e. the equivalent of "Available in iOS since version foo, OSX since version bar"?
A good starting point is that UIKit is for iPhone only, so any class starting with "UI..." wont be available on Mac (ex: UILabel, UITableView, etc)
Classes from the foundation Framework, starting with "NS..." are all available on MacOS, but not all are available on iOS.
In each class Reference documentation you have an "Availability" note at the beginning and sometimes a specific notes in the "Overview" section.
For example: NSAttributedString
Availability
Available in Mac OS X v10.0 and later.
Overview
iOS Note: In iOS, this class is used primarily in conjunction with the Core Text framework.
Hope this helps,
Vincent

How to write to an XML file from iOS?

I am developing an app for iPad, and I need to modify several attributes in a XML file at runtime.
I found the class NSXMLDocument. But I haven't been able to import it to my project.
Is this class not available for iPhone/iPad development?
Is there some other approach I can consider?
I read about libxml library. Is it my answer or there is a better approach?
NSXMLDocument is MacOS X Cocoa only. You have available on iPhone NSXMLParser, and several external libraries built on libxml2 - TouchXML, KissXML and a couple of others.
Note that KissXML supports writing XML.
Other XML libraries that have been suggested include the XML support from Google Data and VTD-XML.
You are looking for a DOM XML parser, which is best for modification of XML documents. See for example this tutorial - without mapping to and from Model Objects - use the XPath.

Resources