iosios8custom-keyboardios-keyboard-extension

Communicate with Custom Keyboard extension with Host App not working in device but works in simulator


I am working with custom keyboard extension. that almost done but i just facing issue with device when i communicate data with extension and my host app that not woking in device but same thing this working in simulator. My code is following:

HostApp View controller:

 - (void)viewDidLoad {

    _defaultvalue = [[NSUserDefaults alloc] initWithSuiteName:@"group.myapp.myappname.targetKeyboard"];
    [_defaultvalue setBool:YES forKey:@"Layout"];
    [_defaultvalue synchronize];
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (IBAction)RightAction:(id)sender {


    _defaultvalue = [[NSUserDefaults alloc] initWithSuiteName:@"group.myapp.myappname.targetKeyboard"];
    [_defaultvalue setBool:YES forKey:@"Layout"];
    [_defaultvalue synchronize];

}

- (IBAction)leftAction:(id)sender {

    _defaultvalue = [[NSUserDefaults alloc] initWithSuiteName:@"group.myapp.myappname.targetKeyboard"];
    [_defaultvalue setBool:NO forKey:@"Layout"];
    [_defaultvalue synchronize];
}

And i check this BOOL value in my extension target using following code and change keyBoard layout according to my need:

-(void)LoadKeyboardview
{

_defaultvalue = [[NSUserDefaults alloc] initWithSuiteName:@"group.myapp.myappname.targetKeyboard"];

        if([_defaultvalue boolForKey:@"Layout"])
        {
            self.ObjKeyLayout=[[[NSBundle mainBundle]loadNibNamed:@"keyboardLayout" owner:nil options:nil]objectAtIndex:0];
            [self addGesturToKeyBoard];
            self.inputView =self.ObjKeyLayout;

        }
        else{

            self.ObjKeyLayout=[[[NSBundle mainBundle]loadNibNamed:@"leftLayout" owner:nil options:nil]objectAtIndex:0];
            [self addGesturToKeyBoard];

            self.inputView =self.ObjKeyLayout;

        }

}

That same code working well in simulator ios8 device iPhone5. please is there any more code needed for this i read in apple doc that said NSUserDefaults initWithSuiteName help me in this thank you.

UPDATE:

I have already set RequestsOpenAccess in plist and at setting->keyboard-customkeyboar->Full Access ON

My extention Plist:

enter image description here


Solution

  • I got solution that i create new provisional profile and enable app-groups and setting app group from my Xcode project from target-->capability--Expand App Group and by tap on + add app group like following screenshot:

    enter image description here

    And doing same thing for my keyboard extension target. Then i used this setting app groups identifier in NSuserDefault:

     _defaultvalue = [[NSUserDefaults alloc] initWithSuiteName:@"group.keyboaredExtention"];
         [_defaultvalue setBool:NO forKey:@"Layout"];
        [_defaultvalue synchronize];
    

    now that working fine in my device and simulator. hope that helps to others.