I am trying to use private frameworks in my app which is not going to app store. Can anyone guide me, how to use private headers generated using class-dump in my ios application.
Below link is listing some private frameworks generated using class-dump. I am trying to import SringBoardServices.h in my MyClass.m file, but i am unable to access it. I am creating an object to SringBoardServices.h like
SringBoardServices *ref = [[SringBoardServices alloc]init];
and trying to access it's methods like ref.method_name. Whether it is a right approach to use private frameworks?
LINK: private-frameworks
I tried using Class myclass = NSClassFromString(#"SpringBoardServices");
id myobj = [[myclass alloc] init]; , but unable to access SpringBoardServices methods.
Related
I'm currently working on moving one of our apps dependencies from Cocoapods to SPM. The dependency is written purely in Swift, but our codebase using it is both ObjC and Swift.
The problem I'm running into now is that anytime a class from the SPM library is defined in an ObjC class, it works, but if Swift tries to reference the property (from the ObjC class) it throws the error message: Value of type SwiftClass has no member libraryClass.
Before moving this package into SPM, Swift files had no issue referencing ObjC definitions of the librarys' classes. Now, anywhere in the app we try to do that the compiler doesn't have access to them.
The code structure looks something along the lines of this, stripped down to keep things minimalistic.
#objc
public class LibrarySwiftClass: NSObject {
etc etc
}
#interface ObjectiveCClass
#class LibrarySwiftClass;
#property (nonatomic, strong) LocalSwiftClass *localClass;
#property (nonatomic, strong) LibrarySwiftClass *libraryClass;
#end
extension ObjectiveCClass {
#objc
func checkPropertyValue() {
let testValue1 = self.localClass <----- This works correctly with no issue
let testValue2 = self.libraryClass <----- The above error happens here
}
}
NOTE: For this example the Swift class is an extension of the Objective C class, but there are other spots in the app where the Swift class isn't related to the ObjC class and they're still failing.
I put in breakpoints to check, and upon using self.value(forKey: "objCProperty") in the swift class, it does show it correctly. Also, there are other non-SPM classes in the ObjC file that are able to properly be referenced with no issue.
I've tried including the ObjC files in the bridging header, and a couple other solutions to get the Swift file access to this property, with no luck. Seems like a very specific error case when setting up SPM. Anyone have any ideas?
Is it possible that I give admob id in one place in xcode and use it anywhere else in the code, just like in android studio strings implementations or do I need to provide it everytime I create admob ad
You can define your admob key in appDelegate to use in all ViewControllers check below steps:
Create appDelegate shared instance using below code:
static var sharedInstance : AppDelegate!
Define your admob id like below:
let adMobId = "abcd1234"
Now you can use your admob id in any class with below code:
AppDelegate.sharedInstance.adMobId
Create a new Swift class with name Constants and assign values to your admob_banner and admob_home like this
import Foundation
let admob_banner = "your banner id"
let admob_home = "your home id"
Now you can use these variables anywhere in your project
I use a native module that works great for getting device info in React Native, in the JS code. I'd like to also make use of it's functionality in other native (Objective-C) code.
Is it possible to access functionality of React Native custom modules from other native code?
You can either access the functionality directly (using -[RNDeviceInfo deviceName] method) or using the way React Native is accessing it, that is:
RNDeviceInfo *rn = [[RNDeviceInfo alloc] init];
NSLog(#"Device Name: %#", [rn constantsToExport][#"model"]);
I found one solution, that is admittedly a bit of a kludge. It does work, but I would imagine this is far from ideal.
At the top of the class that utilizes this code:
#interface RNDeviceInfo ()
- (NSString*) deviceName;
#end
Then I can make use of it like so:
RNDeviceInfo *rn = [[RNDeviceInfo alloc] init];
NSLog(#"Device Name: %#", [rn deviceName]);
I downloaded SpringBoardServices.h file given in SpringBoardServices and added it to my project. But how to access one of the method present inside SpringBoardServices.h file. I am trying to call BOOL SBSProcessIDForDisplayIdentifier(CFStringRef identifier, pid_t *pid); this method present inside SpringBoardServices.h from MyClass.m file. How to call above method from my .m file?
I used below approach, but it is returning null.
Class myclass = NSClassFromString(#"SpringBoardServices");
NSLog(#" myclass %#", myclass); //null
id myobj = [[myclass alloc] init];
I downloaded SpringBoardServices.h file from this link.
There are couple of methods to access C methods from private framework:
Method 1:
Link a private framework (similar to the way how you link public framework)
Include .h file
Do a call:
SBSProcessIDForDisplayIdentifier(...)
Method 2:
Load framework in runtime using dlopen
Find a method using dlsym
Do a call
BTW. This is applicable to C method's and second method won't work for ObjectiveC methods.
NOTE: Yes, I know iOS 6 is under NDA. This question has nothing to do with iOS 6, expect for the fact that the class that I'm referencing is new in iOS 6.
I'm creating a static framework for use in several of my projects, which allows me to use a new API in iOS 6 if it's available, and if it's not it'll fall back to an iOS 5 equivalent. However, although I make sure to always check if a class is valid before using it like so:
if ([NewClass class]) {
NewClass *newClass = [[NewClass alloc] init];
// etc.
}
Whenever I launch my app in the iOS 5 Simulator, I get the following error:
dyld: Symbol not found: _OBJC_CLASS_$_NewClass
(where NewClass stands for the iOS 6 class).
This seems to be an issue just with using a static library, as if I include the certain files that reference the API directly in my project and reference them, it will launch with no issues. I've even tried weak-linking the static library, and it still crashes. The only option that works is weak-linking UIKit, but I would prefer to not have to do that due to UIKit being quite a large framework, and weak-linking takes extra time.
So basically, what can I do to weak link this class in the static library itself?
I guess your IPHONEOS_DEPLOYMENT_TARGET is not set to iOS 5? I just had the same error, because it was already on iOS 6. After setting it to iOS 5, everything was fine.
You can find the configuration both under Target->BuildSettings->IPHONEOS_DEPLOYMENT_TARGET and under Target->Summary->iOS Application Target.
Another approach to avoid this kind of error would be this:
Class myClass = NSClassFromString(#"NewClass")
if( myClass ) {
NSObject *myResult = [myClass aMethod:#"Hello World"];
}