Reputation: 2979
i have done sample action extension app. am not able to get host app request data.i think is there some issue with this code.
Host App request code
NSDictionary *request = @{@"username”:@“username”,@“password”:@“password”};
UIActivityViewController *extensionController = [[UIActivityViewController alloc] initWithActivityItems:@[request] applicationActivities:nil];
extensionController.popoverPresentationController.sourceView = self.view;
[self presentViewController:extensionController animated:YES completion:nil];
App Extension code
NSExtensionItem *inputItem = self.extensionContext.inputItems[0];
NSItemProvider *itemprovider = inputItem.attachments[0];
[itemprovider loadItemForTypeIdentifier:(NSString *)kUTTypePropertyList options:nil completionHandler:^(NSDictionary *item, NSError *error) {
NSDictionary *results = (NSDictionary *)item;
NSLog(@“Host app Request Data=%@",results);
}];
am not sure what's wrong above code, can anyone help me.. thanks
Upvotes: 2
Views: 944
Reputation: 11
Turn on App Groups and use NSUserDefaults
Turn on App Groups and add group name in your both host target and extension target Capabilities
Input set data in host app source
//use our group user defaults NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.organization.ProductName"]; //set a greeting [defaults setObject:@"username" forKey:@"username"]; [defaults setObject:@"password" forKey:@"password"]; //synchronise [defaults synchronize];
//use our group user defaults NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.organization.ProductName"]; //get the greeting NSString *username = [defaults stringForKey:@"username"]; NSString *password = [defaults stringForKey:@"password"]; //check if greeting isn't empty NSLog(@"username = %@ / password = %@", username, password);
Upvotes: 1