iOS Extension kJavaScriptFinalizeArgumentKey - ios8

The iOS 8 Extension SDK allows you to interact with a web pages using JavaScript.
The guide references a kJavaScriptFinalizeArgumentKey constant to use as a dictionary key when passing data back to the finalize() method in the JS.
Xcode doesn't recognise this, nor the other kJavaScriptResultsKey referenced in the docs.
Does anyone know if this is either not yet implemented, or if I need to import a module for this to work?

replace 'kJavaScriptFinalizeArgumentKey' with 'NSExtensionJavaScriptFinalizeArgumentKey'
so the SDK sample should be
NSExtensionItem *extensionItem = [[NSExtensionItem alloc] init];
extensionItem.attachments = #[[[NSItemProvider alloc] initWithItem: #{NSExtensionJavaScriptFinalizeArgumentKey: #{#"bgColor":#"red"}} typeIdentifier:(NSString *)kUTTypePropertyList]];
[self.extensionContext completeRequestReturningItems:#[extensionItem] completionHandler:nil];

Related

NSNetService says it is published, but it isn't visible on the network

I'm working on a little iOS app for my own use (initially, at least) and I thought I would use Bonjour to configure networking between two iOS devices.
My server's interface defines
NSNetService *netService;
and the implementation uses the following code to advertise its existence:
const NSString *kSEBonjourServiceDomain = #""; //use defaults
const NSString *kSEBonjourServiceName = #"_test._tcp.";
//...
netService = [[NSNetService alloc] initWithDomain:(NSString *)kSEBonjourServiceDomain type:(NSString *)kSEBonjourServiceName name:#"" port:sin.sin_port];
if (netService)
{
netService.delegate = self;
netService.includesPeerToPeer = YES;
[netService publish];
}
else NSLog(#"Failed to create NSNetService");
When I start the server, my NSNetService object does call the -netServiceDidPublish: delegate method, but when I use Discovery to browse the bonjour services on my network, my service doesn't appear. Apart from the const strings, this code is the same as some code in one of my Mac apps (which works as expected) and also very similar to Apple's sample code.
I've gone through all the options in Xcode's capabilities tab in case I needed to add something there, but I can't see anything relevant. I've also read a bunch of documents and tutorials that don't mention having to do anything more than that, but it wouldn't surprise me to learn that this only works on iOS if you set an obscure build setting to a string that you had to learn about by reading the Human Interface Guidelines for watchOS last September.
So, can anyone enlighten me? What am I missing?
Thanks in advance!
It turned out that due to a silly error elsewhere in my code, sin.sin_port was set to 0 by the time I was registering my NSNetService. Although NSNetService doesn't see this as a problem, it was causing the service to be ignored by service browsers.
So the answer is, a service with a port of 0 will register without error, but won't work.
Thanks to gaige for the assistance.

How to force NSArrayController to reload MOC contents to reflect latest fresh data

I am working on a Mac & iOS App, with iCloud CoreData in between to synchronize the data.
When I update some thing from iOS App, and the updates are already migrated to the PersistentStore in Mac App while the Mac App is running. The problem is I cannot find an effective way to force the NSArrayController to reload all data from the store.
tried -(void) fetch:(id)sender; only can see the delete or added entity, but the updated model property not refreshed...
Please help. Thanks
If you see the latest data in the managed object context, but not in the array controller, you want:
[_yourManagedObjectContext processPendingChanges];
[_yourArrayController fetchWithRequest:nil merge:YES error:&error];
[_yourArrayController rearrangeObjects];
I use this in a Mac/iOS iCloud app to update the Mac app's data when the iCloud store changes.
Following is the reply from Apple's Developer Technical support. It worked for me. Thanks all for providing solutions.
For the OS X app, when reloadFetchResults is called, you can ask the NSManagedObjectContext to reset itself and perform the fetch again.
- (void)reloadFetchedResults:(NSNotification *)note
{
NSDictionary *userInfoDict = [note userInfo];
NSManagedObjectContext *moc = self.coreDataController.mainThreadContext;
// this only works if you used NSMainQueueConcurrencyType
// otherwise use a dispatch_async back to the main thread yourself
//
[moc performBlock:^{
[self mergeiCloudChanges:userInfoDict forContext:moc];
[moc reset];
[self.tableArrayController fetch:self];
}];
}
I've found that
[self.managedObjectContext reset];
[myArrayController fetch:self];
forces my NSTableView (with NSArrayController) to re-populate and display newly processed NSManagedObjects.
in case someone else finds this...
in my case, I was building the array from user interaction (not Core Data), and then trying to show the tableView when they were done (on the same window)... and of course... seeing nothing!
[arrayController rearrangeObjects];
just before I wanted to show the tableView fixed it for me.

CPOpenPanel not working in Cappuccino

I am trying to use CPOpenPanel to select a file for upload,
when I call runModal upon CPOpenPanel object , it is throwing an exception as
CPInvalidArgumentException: - [CPOpenPanel runModel] unrecognized selector sent to instance 0x005585
Does CPOpenPanel still has bugs in cappuccino framework ?
Am I missing something ? I just created an object and calling runModal on that object.
CPOpenPanel only works in our NativeHost environment, not the the browser. The same for CPSavePanel. Those are about the only classes this is true for.
The error show you that the runModel doesn't exist for CPopenPanel. it's not runModel but runModal, and If you want to upload a file look at
this thread https://groups.google.com/forum/m/?fromgroups#!topic/objectivej/6ZupNuR5DIw
It's about 2 libs for uploading file with a simple button or drag and drop upload.
Ben
This should work with NativeHost (jake run-desktop):
var panel = [[CPOpenPanel alloc] init];
[panel runModal];

checking app download completion from my own app

so what I'm trying to do here is the following: let's say the user has already installed my app, app "A", from the store. On certain conditions, app "A" will open an URL pointing to a specific app page,app "B", on the App Store passing a redemption code so the user of app A is able to download app "B" without paying any additional money. So here's what I'm doing:
NSString *urlBase = #"https://phobos.apple.com/WebObjects/MZFinance.woa/wa/freeProductCodeWizard?code=";
NSURL *urlRedemptionCode = [NSURL URLWithString:[urlBase stringByAppendingString:code]];
[[UIApplication sharedApplication] openURL:urlRedemptionCode];
This is working fine, so the question is: how do I know that the download of app "B" was completed correctly (or with errors) so I can take appropriate action in app "A"?
Thanks so much.
You could use NSURLConnection in combination with NSURLRequest and NSURLResponse instead of directly calling [[UIApplication sharedApplication] openURL:yourURL].
NSURLConnection will allow you to set a delegate that will be notified when:
Data is (partially) received
Connection failed
Download finished
etc.
Check Using NSURLConnection at the official documentation.

SMJobBless - documentation on when it asks for admin password

I cannot seem to locate any documentation on this, so hopefully someone can confirm the behavior I am seeing with Apple's sample SMJobBless code.
I was under the impression that it would only ask for an admin password if it detected a that a new version of the helper tool needed to be installed.
However, this impression is apparently incorrect.
The behavior I am seeing under 10.6 is that if I launch the app for the first time, it will ask for the password. If I launch almost immediately, it won't. However, if I wait a long enough time, it will ask for the password again. During all of this, the helper tool does not change.
Can anyone point to documentation that defines this as the correct behavior?
If anyone is interested, this (probably) turned out to be a bug and one has been filed. rdar://10280469
The way the system currently works is that it will ask for an admin password every time regardless of whether or not the SMJobBless function needs to install the helper tool or not. The bug is (probably) that a admin password request should not be made if the helper tool does not need to be installed (for example, it is already installed and has the same version as the one in the app bundle).
So, what this means is that the determination of whether or not the helper tool needs to be installed needs to be made before a call to SMJobBless and SMJobBless should only be called if it is already known the helper tool needs to be installed.
In my case, I only need to check whether the tool is installed (SMJobCopyDictionary handles this) and, if the tool is installed, whether or not it's version is older then the version of the tool in my app bundle.
Some (incomplete) code to check whether the tool is installed and what the versions are is below.
There is another alternative to do a version check of the helper tool which is for the helper tool to receive a request for it's version and for it to send a version reply back. Personally, I like the method below, but wanted to mention this alternative as it may be the best path in some situations.
NSDictionary* installedHelperJobData;
installedHelperJobData = (NSDictionary*)SMJobCopyDictionary( kSMDomainSystemLaunchd, (CFStringRef)#"com.apple.bsd.SMJobBlessHelper" );
NSString* installedPath = [[installedHelperJobData objectForKey:#"ProgramArguments"] objectAtIndex:0];
NSURL* installedPathURL = [NSURL fileURLWithPath:installedPath];
NSDictionary* installedInfoPlist = (NSDictionary*)CFBundleCopyInfoDictionaryForURL( (CFURLRef)installedPathURL );
NSString* installedBundleVersion = [installedInfoPlist objectForKey:#"CFBundleVersion"];
NSInteger installedVersion = [installedBundleVersion integerValue];
NSLog( #"installedVersion: %ld", (long)installedVersion );
NSBundle* appBundle = [NSBundle mainBundle];
NSURL* appBundleURL = [appBundle bundleURL];
NSURL* currentHelperToolURL = [appBundleURL URLByAppendingPathComponent:#"Contents/Library/LaunchServices/com.apple.bsd.SMJobBlessHelper"];
NSDictionary* currentInfoPlist = (NSDictionary*)CFBundleCopyInfoDictionaryForURL( (CFURLRef)currentHelperToolURL );
NSString* currentBundleVersion = [currentInfoPlist objectForKey:#"CFBundleVersion"];
NSInteger currentVersion = [currentBundleVersion integerValue];
NSLog( #"currentVersion: %ld", (long)currentVersion );

Resources