following is the code i am using to activate system extension on macos catalina
{
OSSystemExtensionRequest *SysReq = [[OSSystemExtensionRequest alloc] init];
[OSSystemExtensionRequest activationRequestForExtension:SysReq.identifier queue:dispatch_get_main_queue()];
SysReq.delegate = RequestDelegate;
[OSSystemExtensionManager.sharedManager submitRequest:SysReq];
}
but after i reach the end of the current function i get an exception.
following are the details ---
Thread 4: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
Thread 4 Queue : com.apple.root.default-qos (concurrent)
0 0x00007fff49aa734a in -[OSSystemExtensionRequest failedWithError:] ()
You need to pass bundleId as NSString.
[OSSystemExtensionRequest activationRequestForExtension:#"yourOrg.name.appname"
queue:dispatch_get_main_queue()];
And make sure your entire code is on a dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^() {...
Related
I have a function that has a problem in it. The following line seems to require a delay in order to accurately process whatever data it's processing, but it's not getting that time and and as a result I'm getting the wrong result. The following line:
self.failure = failure
Seems to need about 5-7 seconds to execute, but the problem is that the next line of code is executed before it can finish.
I need to setup self.failure = failure in a way where the rest of the code in the function executes inside a completion block once that line has finished. I'm just not sure how to do it.
I've tried creating a typedef for a completion block, but I have no idea how and where to execute it.
- (void)start:(BMPlaybackStartupProcessCompleteBlock)completion
failure:(BMPlaybackStartupProcessFailureBlock)failure // what is the error code at the start and end of this method?
{
NSParameterAssert(completion);
NSParameterAssert(failure);
self.completion = completion;
self.failure = failure;
NSOperation *jailBreakOperation = [self jailBreakCheckOperation];
NSOperation *metadata = [self metadataOperation];
NSOperation *ads = [self adsOperation];
NSOperation *mediaPlayer = [self mediaPlayerOperation];
NSOperation *progress = [self progressTrackerOperation];
NSOperation *final = [self finalOperation];
[final addDependency:mediaPlayer];
[final addDependency:progress];
if (ads)
{
[final addDependency:ads];
[ads addDependency:metadata];
}
[mediaPlayer addDependency:metadata];
[progress addDependency:metadata];
[metadata addDependency:jailBreakOperation];
[self.queue addOperation:final];
if (ads)
{
[self.queue addOperation:ads];
}
[self.queue addOperation:mediaPlayer];
[self.queue addOperation:progress];
[self.queue addOperation:metadata];
[self.queue addOperation:jailBreakOperation];
// INPUTS:
// - content ID
// - metadata component
// - media player component
// - ads component
// - location manager if required
// - auto play?
// OUTPUTS:
// - Possibly an error if not successful
// - metadata
// - playback details
}
I want self.failure = failure to finish BEFORE the NSOperationQueue stuff executes.
NSOperation has completionBlock property.
#property(copy) void (^completionBlock)(void);
So you can perform your operation like this. This will handle failure if occured.
Create `error` block level property to save error while operation.
nsOperatorObject.completionBlock(^{
if (self.error) {
self.failure();
} else {
self.completion();
}
});
This might be wrong answer . Sorry for that :)
According to documentation of google-api-objectivec-client library:
Queries made from any thread can be called back on a background thread by providing a background queue, as in this example:
service.delegateQueue = [[NSOperationQueue alloc] init];
When a delegate queue is specified, there is no requirement for a run loop to be running on the thread that executes the query.
But, it does not work. Handlers are still executed on a main thread.
Question:
How to tell Google Drive service to execute handlers on the background thread?
Code snippet to reproduce
Podfile:
pod 'GTMOAuth2'
pod 'GoogleAPIClient/Drive'
Somewhere in application:
#import "GTLDrive.h"
#import "GTMOAuth2Authentication.h"
...
- (void) applicationDidFinishLaunching:(NSNotification *) aNotification {
service = [[GTLServiceDrive alloc] init];
service.retryEnabled = YES;
service.authorizer = _authorizer //from GTMOAuth2WindowController
service.delegateQueue = [[NSOperationQueue alloc] init];
GTLDriveFile * tempadFolder = [GTLDriveFile object];
folder.name = #"folder-name";
folder.mimeType = #"application/vnd.google-apps.folder";
GTLQueryDrive * query = [GTLQueryDrive queryForFilesCreateWithObject: folder uploadParameters: nil];
[service executeQuery: query completionHandler:
^(GTLServiceTicket * ticket,
GTLDriveFile * updatedFile,
NSError * error) {
if ([NSThread isMainThread]) {
NSLog(#"This is a main thread!");
}
}
}
This bug was fixed in this commit and released in GoogleAPIClient 1.0.2.
For now code behaves according to documentation:
Queries made from any thread can be called back on a background thread by providing a background queue, as in this example
service.delegateQueue = [[NSOperationQueue alloc] init];
I have to programmatically terminate (not forcibly) an application from my Cocoa code.
Actually, here's what it looks like:
-(BOOL) terminateAppWithBundle:(NSString*)bundle {
NSArray* array = [NSRunningApplication runningApplicationsWithBundleIdentifier:bundle];
if ([array count] > 0){
NSRunningApplication* app = (NSRunningApplication*)[array objectAtIndex:0];
[array makeObjectsPerformSelector:#selector(terminate)];
float time = 0;
while (!app.isTerminated){
[NSThread sleepForTimeInterval:0.2];
time += 0.2;
if (time >= 15){
return NO;
}
}
}
return YES;
}
It works very well... but only on Snow Leopard and Lion.
On Leopard (which i would like to support) the application crashes on start with this error message:
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000
Crashed Thread: 0
Dyld Error Message:
Symbol not found: _OBJC_CLASS_$_NSRunningApplication
I guess it's because NSRunningApplication is not part of the 10.5 SDK... how can i do the same without using that class?
Solved by myself with AppleScript:
-(BOOL) terminateiTunes {
NSAppleScript *closeiTunes = [[NSAppleScript alloc] initWithSource:#"tell application \"iTunes\" to quit"];
[closeXcode executeAndReturnError:nil];
return YES;
}
I've a problem with an app for Mac that I'm writing in Objective-c.
I've this situation:
In main thread (GUI):
ftEngine = [[FileT alloc] init];
[ftEngine setParameters:searchWord selectedEngine:[[pbEngines selectedItem] title] actualPage:0];
NSThread* thFileT = [[NSThread alloc] initWithTarget:ftEngine selector:#selector(setTotalResult) object:nil]; [thFileT start];
In child (ftEngine previous declared):
-(void)setTotalResult {
NSError* nsError = nil;
NSURL* urlCompleteUrl = [NSURL URLWithString:m_completeSearchWord];
}
m_completeSearchWord is initialized by setParameters function previously utilized.
And now.. my problem is:
When thread is started, it call setTotalResult function and i'll get an exception when I try to use m_completeSearchWord.
It's strange becacuse if I don't use a thread, all works correctly!
Exception is:
2011-09-08 23:24:06.731 GUI[12935:1a07] *** -[CFString respondsToSelector:]: message sent to deallocated instance 0x1003cc650
It sounds like you may not have retained m_completeSearchWord correctly when you initialized it. Add the body of -setParameters if you want help confirming that.
When calling selectors in a new thread, make sure that the selector has been properly wrapped with an autorelease pool :
-(void) setTotalResult {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
...
[pool release];
}
I see all manner of memory related issues when I forget to add the pool and your error definitely rings a bell.
I was trying out a sample thread program from google and i am getting a runtime exception.
Is there any website that gives an example of how to use runloops along with threads.
I need to set two events and spawn a thread and to do another function parallely.
// Runner.m
#import "Runner.h"
#implementation Runner
- (void)rumMe:(id)ignored {
NSLog(#"Running with threads!!");
}
#end
// Runner.h
#interface Runner : NSObject
-(void)rumMe:(id)ignored;
#end
// Thread1.m
#import <Foundation/Foundation.h>
#import "Runner.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Runner* runner = [Runner new];
[NSThread detachNewThreadSelector:#selector(runMe:) toTarget:runner withObject:nil];
[pool drain];
return 0;
}
Runtime Exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '***
-[NSThread initWithTarget:selector:object:]: target does not implement selector (***
-[Runner runMe:])'
First part: you had a typo
// method declaration
rumMe: with an _m_
// call
runMe: with an _n_
Second part: your main function is returning and causing the program to exit before you have given the thread a chance to do anything. In this simple simple example, you could simply
sleep(2);
right after the call to detachNewThreadSelector:
In more complex cases, you might need to make a call to CFRunLoopRun(); on the main thread, or take other action to keep the second thread alive.
You have made a typo. The method in Runner is defined as rumMe, but in the main program you use runMe.