Using Objective-c hidden api (iphone) - objective-c

I'm trying to use this guthub According to this link for using objective c private api but the documentation is pretty lousily.
I copied past the exemple code to my xcode but I'm getting compilation error.
NSBundle *b = [NSBundle bundleWithPath:#"/System/Library/PrivateFrameworks/TelephonyUI.framework"];
BOOL success = [b load];
Class SKTelephonyController = NSClassFromString(#"SKTelephonyController");
//this line cussing the error
**id tc = [SKTelephonyController sharedInstance];**
NSLog(#"-- myPhoneNumber: %#", [tc myPhoneNumber]);
NSLog(#"-- imei: %#", [tc imei]);
error:
No known instance method for selector 'myPhoneNumber'
Can someone please have a guide or something to get started.
Oh, I know my app will not pass apple validation, I dont need there validation its an internal app.
thanks.

First of all, the example doesn't say to load SKTelephonyController, it says to load GAIA.framework
Second is that SKTelephonyController and GAIA are not available for iOS7 (they was working on iOS 6)
Here is example, how you need to dummy declare an interface, and make calls.
#interface SKTelephonyController : NSObject
+ (id)sharedInstance;
+ (NSString *)myPhoneNumber;
+ (NSString *)imei;
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSBundle *b = [NSBundle bundleWithPath:#"/System/Library/PrivateFrameworks/GAIA.framework"];
BOOL success = [b load];
if (!success) {
NSLog(#"Can't load bundle");
return;
}
NSLog(#"-- imei: %#", [[SKTelephonyController sharedInstance] imei]);
}

Related

MLKit object detector is crashing in MLKObjectDetectorOptions

I am trying to fetch object frames from given image using MKLKIT. But my code is getting crashed
MLKObjectDetectorOptions *options = [[MLKObjectDetectorOptions alloc] init];
#import <Foundation/Foundation.h>
#import <MLKitObjectDetection/MLKitObjectDetection.h>
#import <MLKitObjectDetectionCommon/MLKObjectDetector.h>
#import <MLKitObjectDetection/MLKObjectDetectorOptions.h>
#import <MLKitObjectDetectionCommon/MLKObject.h>
#import <MLKitVision/MLKVisionImage.h>
#import "MLKitObjectDetection.h"
#implementation MLObjectDetection
- (NSMutableArray*)detectFrame:(UIImage*)image{
NSMutableArray *frames = [NSMutableArray new];
// Multiple object detection in static images
MLKObjectDetectorOptions *options = [[MLKObjectDetectorOptions alloc] init];
options.detectorMode = MLKObjectDetectorModeSingleImage;
options.shouldEnableMultipleObjects = YES;
MLKObjectDetector *objectDetector = [MLKObjectDetector objectDetectorWithOptions:options];
MLKVisionImage *visionImage = [[MLKVisionImage alloc] initWithImage:image];
visionImage.orientation = image.imageOrientation;
NSError *error;
NSArray *objects = [objectDetector resultsInImage:visionImage error:&error];
if (error == nil) {
return frames;
}
if (objects.count == 0) {
// No objects detected.
}
for (MLKObject *object in objects) {
[frames addObject:[NSValue valueWithCGRect:object.frame]];
}
//TODO release memory
return frames;
}
#end
When your code crash, did you try to run your code inside Xcode and look into the console in the debug area to check what error message was printed out there? Usually that will give you some clue as to what led to the crash.
Based on your code, are you calling the detectFrame: method from the main UI thread? The synchronous MLKObjectDetector#resultsInImage:error: should never be called from the main UI thread. This is documented in its API reference. You can check out ML Kit's quickstart sample app here. It shows how to call both the synchronous MLKObjectDetector#resultsInImage:error: API and the asynchronous MLKObjectDetector#processImage:completion: API.

worklight 6.0 adapter native ios to hybrids application

I can able to call worklight 6.0 adapter invoke in IOS native code (using Objective-C) but i can not read adapter JSON response using cordova plugin from my hybrids application.
// invoke the adapter
MyConnectListener *connectListener = [[MyConnectListener alloc] initWithController:self];
[[WLClient sharedInstance] wlConnectWithDelegate:connectListener];
// calling the adapter using objective-c
WLProcedureInvocationData *myInvocationData = [[WLProcedureInvocationData alloc] initWithAdapterName:#"HTTP_WS_ADPTR" procedureName:#"getBalance"];
MyInvokeListener *invokeListener = [[MyInvokeListener alloc] initWithController: self];
[[WLClient sharedInstance] invokeProcedure:myInvocationData withDelegate:invokeListener];
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:responseString];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
// hybrids application call the native code
cordova.exec(sayHelloSuccess, sayHelloFailure, "HelloWorldPlugin", "sayHello", [name]);
above the cordova.exec success and failed method is not return the value.
but i can not able to parse the value from CDVPluginResult method. Anybody please advice me. how can i read the adapter for IOS native from hybrids application.
Several things to note:
You are using Worklight 6.0.0.x. In Worklight 6.0.0.x there is no proper session sharing between web and native views. Meaning, if you will for example call the WL.Client.connect() method in the web view and then do a connect() and adapter invocation in the native view - these calls will not share the same session which can lead to race condition errors, inability to share state between the views and other unexpected events. Not recommended.
If this is the approach you're looking to implement in your Hybrid application it is therefore highly recommended that you will upgrade to either MobileFirst (previous known as "Worklight") v6.3 or v7.0 where session sharing between web and native views is now available out-of-the-box.
Although you might just want to opt to call the adapter from the JS code...
To get this to work as-is in your supplied project, you can change the implementation based on the below.
Note that the implementation below was based on MFP 7.0, as such the adapter invocation code will not work in your 6.0.0.0x codebase. You will need to alter it based on your own code in v6.0.0.x:
sayHello.h
#import <Foundation/Foundation.h>
#import <Cordova/CDV.h>
#import "WLClient.h"
#import "WLDelegate.h"
#interface SayHelloPlugin : CDVPlugin
- (void)sayHello:(CDVInvokedUrlCommand*)command;
- (void)callResult:(NSString*)response;
#end
sayHello.m
#import "SayHelloPlugin.h"
#import "MyConnectListener.h"
CDVInvokedUrlCommand *tempCommand;
#implementation SayHelloPlugin
- (void)sayHello:(CDVInvokedUrlCommand*)command {
MyConnectListener *connectListener = [[MyConnectListener alloc] init:self];
[[WLClient sharedInstance] wlConnectWithDelegate:connectListener];
tempCommand = command;
}
-(void)callResult:(NSString*)response{
CDVPluginResult *pluginResult =
[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:response];
[self.commandDelegate sendPluginResult:pluginResult callbackId:tempCommand.callbackId];
}
#end
MyConnectListener.h
#import <Foundation/Foundation.h>
#import "WLClient.h"
#import "WLDelegate.h"
#import "SayHelloPlugin.h"
#interface MyConnectListener : NSObject <WLDelegate> {
#private
SayHelloPlugin *sh;
}
- (id)init: (SayHelloPlugin *)sayHello;
#end
MyConnctListener.m
The responseText line is commented out because the data retrieved from the adapter was too large I suppose, so it's best to return only what you really need and not all of it.
#import "MyConnectListener.h"
#import "WLResourceRequest.h"
NSString *resultText;
NSString *request;
#implementation MyConnectListener
- (id)init: (SayHelloPlugin *) sayHello{
if ( self = [super init] )
{
sh = sayHello;
}
return self;
}
-(void)onSuccess:(WLResponse *)response{
NSURL* url = [NSURL URLWithString:#"/adapters/testAdapter/getStories"];
WLResourceRequest* request = [WLResourceRequest requestWithURL:url method:WLHttpMethodGet];
[request setQueryParameterValue:#"['technology']" forName:#"params"];
[request sendWithCompletionHandler:^(WLResponse *response, NSError *error) {
if(error != nil){
resultText = #"Invocation failure: ";
resultText = [resultText stringByAppendingString: error.description];
[sh callResult:resultText];
}
else{
resultText = #"Invocation success. ";
//resultText = [resultText stringByAppendingString:response.responseText];
[sh callResult:resultText];
}
}];
}
-(void)onFailure:(WLFailResponse *)response{
resultText = #"Connection failure: ";
resultText = [resultText stringByAppendingString:[response errorMsg]];
NSLog(#"***** failure response: %#", resultText);
[sh callResult:resultText];
}
#end

IOS App Action extension is not closing

I am facing app extension close issues , please tell me if anyone know what wrong am doing.I am using action extension after preform some action inside extension i need to return response back.
Sample Code
// With Success Case
- (void) completeActionWithItems: (NSString *) response {
NSExtensionItem *extensionItem = [[NSExtensionItem alloc] init];
extensionItem.attachments = #[[[NSItemProvider alloc] response typeIdentifier: (NSString *)kUTTypePlainText]];
[self.extensionContext completeRequestReturningItems: #[extensionItem] completionHandler: nil];
}
// With Error Case
- (void) completeActionWithError: (NSError *) error {
[self.extensionContext cancelRequestWithError: error];
}
With Success Case working fine but some time is not closing,
With Error Case not working above code.
Please let me know what went wrong.Thanks
When you create an action extension, this is the default method which will close the Action Extension View Controller:
- (IBAction)done {
// Return any edited content to the host app.
// This template doesn't do anything, so we just echo the passed in items.
[self.extensionContext completeRequestReturningItems:self.extensionContext.inputItems completionHandler:nil];
}
Since this method is already provided, you should just try calling it from your success method.
// With Success Case
- (void) completeActionWithItems: (NSString *) response {
NSExtensionItem *extensionItem = [[NSExtensionItem alloc] init];
extensionItem.attachments = #[[[NSItemProvider alloc] response typeIdentifier: (NSString *)kUTTypePlainText]];
[self.extensionContext completeRequestReturningItems: #[extensionItem] completionHandler: nil];
// Call to "done" method
[self done];
}

"Root" key from plist is not recognized from the AppDelegate?

i have a simple question : why does "origineArray" return (null) ? i found out that if i put all the code in the RootViewController it works, but if i put it in the AppDelegate (as it is in a sample code, i don't which way is better?) , it does not recognize the "Root" key :
- (id)init {
self = [super init];
if (self){
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:#"origine.plist"];
origine = [[NSDictionary dictionaryWithContentsOfFile:finalPath]retain];
}
return self;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(#"origine data : %#", origine);
NSArray *origineArray = [origine objectForKey:#"Root"];
NSLog(#"origineArray data : %#", origineArray);
Thanks for your help
If your application delegate is created in a nib file, the init method is not called. Items in nibs are archived already initialized.
If you want initialization of an object loaded from a NIB, implement the - (void) awakeFromNib method.
You are logging the "origine" dictionary, what does it log to the console? If the "Root" key is not there then you are not opening the right file obviously. If the dictionary is NULL then you need to fix the path.
Are you sure that finalPath contains the right path? It seems that the origin.plist is in the resources folder but you are using the location of your app bundle in the finder.

Objective-C 'RootViewController' may not respond to '-parseXMLFileAtURL:' error in xCode

I have this error when building and running my project in xCode:
RootViewController may not respond to -parseXMLFileAtURL:
I'm attempting to develop the basic Apple RSS Reader from the tutorial at:
http://gigaom.com/apple/tutorial-build-a-simple-rss-reader-for-iphone/
my section of code that this error is occurring in looks like this:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if ([stories count] == 0)
{
NSString * path = #"http://feeds.feedburner.com/TheAppleBlog";
[self parseXMLFileAtURL:path];
}
cellSize = CGSizeMake([newsTable bounds].size.width, 60);
}
can anybody explain why this parseXMLFileAtURL command gives so much heartache?
Thanks
UPDATED***
I also define parseXMLFileAtURL in the same file; however, I placed that section of the code after the viewDidAppear method (my bad). So when I change the order of the methods that error goes away. But when I do that, I get another error, maybe you guys can help with that error too! here it is:
Class RootViewController does not implement the NSXMLParserDelegate protocol
within this section of code:
- (void)parseXMLFileAtURL:(NSString *)URL
{
stories = [[NSMutableArray alloc] init];
NSURL *xmlURL = [NSURL URLWithString:URL];
rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[rssParser setDelegate:self];
[rssParser setShouldProcessNamespaces:NO];
[rssParser setShouldReportNamespacePrefixes:NO];
[rssParser setShouldResolveExternalEntities:NO];
[rssParser parse];
}
The error occurs after the line: [rssParser setDelegate:self]; - what might be wrong with that?
In regards to your second question that RootViewController does not conform to the NSXMLParserDelegate protocol. Just add it like this in your RootViewController.h file:
#interface RootViewController : UIViewController <NSXMLParserDelegate> { .....
Silly question: Does your RootViewcontroller class have a method named -parseXMLFileAtURL: defined? If -parseXMLFileAtURL: comes after the method that calls it, you'll also need to declare it in your header.
Make sure you have parseXMLFileAtURL defined in your RootViewController.m
-(void)parseXMLFileAtURL:(NSString *)url
{
...
}
And make sure you have it defined in your header as:
-(void)parseXMLFileAtURL:(NSString *)url;
Also, make sure that when you try to get the contents from the web, you're using an NSURL, not an NSString. You can instantiate a NSURL with a string by:
NSURL *urlFromString = [[NSURL alloc] initWithString:#"http://..."];