iOS How to use private API? - ios

I don't want to submit this app to AppStore. I've tried for many times but met so many problems :(
I use class-dump to get all the header files of UIKit.framework. In the UIApplication.h generated by class-dump, I saw the method I want to use----launchApplicationWithIdentifier.
Then I put UIApplication.h in my project and import it. Compile, I got a lot of "Redefinition of enumerator...." error because in the UIKit.framework I use previous, there's another UIApplication.h. But this file doesn't have the method launchApplicationWithIdentifier.
If I delete the previous UIKit.framework and import the folder generated by class-dump. Then it appears like a framework but if I unfold it, it's empty.
Then I want to make all generated header files a framework file ant replace the previous UIKit.framework. But I don't know how. As we can see, under the system framework directory, there's a file which has the same name as the framework and has a 'executed shell script' icon. How can I made this file?
I really got confused. Someone can give me a hand? Thank you.

Just specify the private methods in a category interface above the class implementation where you want to use it, like this:
#interface UIApplication (Private)
- (BOOL)launchApplicationWithIdentifier:(id)identifier suspended:(BOOL)suspended;
#end
Don't import the whole class-dump file and link with the original UIKit framework.
You must be very careful when using private API. These methods can change or be removed in future iOS versions!
Check if the method really exists with respondsToSelector: at runtime and be prepared for the case that it does not exist.
I used a secret MapKit feature in my own application and I knew that the private methods only exist in iOS 5. So my app still works in all iOS versions but this feature is only available in iOS 5 (Apple removed or changed it in iOS 6 beta 1).

Related

How to include libsignal-protocol-c in my Swift iOS app?

I would like to write something like import SignalProtocol at the top of one of my Swift files and then be able to call the C functions from libsignal-protocol-c.
libsignal-protocol-c's README says: "When integrating into actual applications, you should not need anything beyond CMake. Alternatively, you may integrate the code using a build system of your choice."
I think I'd like to use the Swift Package Manager to integrate libsignal-protocol-c into my Swift iOS app. Is there a way to automatically generate a manifest file, ie, Package.swift, and a module map, ie, a module.modulemap file, from libsignal-protocol-c's CMake files? Or if I need to create these files manually, what should they include? Otherwise, how would I do this with CMake?
How to import and use libsignal-protocol-c in an existing .xcodeProj? is a similar question but for Objective-C projects.
I'm not sure its an answer but I'm going to start using https://github.com/christophhagen/LibSignalProtocolSwift. Seems like a good start.

importing native iOS framework to nativescript plugin

I'm trying to access an iOS framework class from my NativeScript plugin.
Right now, this plugin only has a SampleClass with a test method that returns a number, but it will change soon. For now, what I'm trying to do is to call the class method from that native framework.
I have seen some examples where the plugin seed extends an iOS base class and creates everything there, but in this case, I want to use a .framework file.
I'm assuming this would be equivalent to use some .aar Android file. In that case, I've seen the call would be made with something like this
var c = java.lang.Class.forName("org.test.plugin.name.MyActivity");
So, I have copied the .framework file to platforms/ios, my question is about how to get this SampleClass method.
Also, I've seen some documentation that recommends the use of CocoaPods. I'm new to iOS development and still don't get this at all, but if my application won't use any native dependency, would this be necessary? Should I need another files? (got a default Info.plist and build.xcconfig)
Thank you for your answers.
Since you are using TypeScript, you have to either declare the classes like,
// iOS
declare var SampleClass;
// Android
declare var org;
then you may access all available packages / classes / methods directly.
// Android
const MyActivity = org.test.plugin.name.MyActivity;
// iOS
SampleClass.new()
If you like intellisense support for these libraries, then you may even generate declaration files for both iOS & Android libraries with the given steps in the docs.

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!

How to create and use an iOS Framework for sharing code with Extensions

How does the minimal setup and usage of a custom iOS framework look like? I starting to look into this in order to share code with a Today Extension.
Here's what I did so far
Added a new Target choosing the Cocoa Touch Framework template and called it TesterKit
Inside the framework I created a new class TestClass.swift
Inside TestClass.swift I created a simple class method class fund tester() printing a string for testing
Looking at my app I can see that TesterKit has been added as Embedded Binaries and Linked Frameworks and Libraries, however it is red
In order to use this new Framework in the app, I added import TesterKit to the top of my AppDelegate
Then I tried to call the class method from the Framework using TestClass.tester(). But instead of showing the log message I get a …
"Use of unresolved identifier"
→ What am I doing wrong? Any wrong assumptions here?
Note: I already watched the WWDC sessions 416 "Building Modern Frameworks" and found the Framework Programmign Guide. If there are any example projects showing how to use such new custom iOS Frameworks, ideally using Swift + integrating this with Today Extensions, that might be helpful, too.
It seems like your import is not failing which means the framework is actually set up correctly...try making the function public.
public func tester() { print("tester()" }

Can you use CFUserNotification with IOS 5.1

I am trying to get a notification to appear when the app is in the background or suspented, as the LocalNotification does not work, I seen mention the CFUserNotification as a potential solution, but when i include the corefoundation framework to my app the CFUserNotification is still no-where to be found, can someone show me how to include CFUserNotification in my project ?
Can you use CFUserNotification with IOS 5.1?
No
If you're not making this for the App Store, you can use private APIs. The way I have used CFUserNotifications is to
Add CoreFoundation.framework to the list of frameworks I link against (maybe this framework is automatically included ... I'm not sure ... I just know that it doesn't hurt to add it explicitly to your project).
The CoreFoundation public APIs still don't have the CFUserNotification functions in the headers, as Justin said. So, you need to manually include a complete CFUserNotification.h header. You can find a copy here. Just copy that whole header file, and include it in your project source directory. Then #import "CFUserNotification.h" where you want to use it.
Then, the compiler will let you access those CFUserNotification APIs. I've done this on iOS 5.0 with success (on a device).

Resources