ios - How to change background color of custom keyboard when button is pressed into host app? -


i trying change custom keyboard background host app reason not work.

i tried nsuserdefaults doesn't work, here code when button pressed host app:

func buttontapaction() {      nsuserdefaults.standarduserdefaults().setinteger(1, forkey: "abc") } 

and way reading values disk execute else condition:

override func viewdidload() {     super.viewdidload()      let abc = nsuserdefaults.standarduserdefaults().integerforkey("abc")     if abc == 1 {         self.view.backgroundcolor = uicolor.redcolor()     }else{         self.view.backgroundcolor = uicolor(red: 241.0/255, green: 235.0/255, blue: 221.0/255, alpha: 1)     }      //other code  } 

i don't know doing wrong.

here full project.

enable app groups both targets

step 1.

enter image description here

same steps , group name should same nuberwidget target keep in mind.

step 2.

enter image description here

step 3.

enter image description here

step 4.code store value

objective c

nsuserdefaults *shareddefaults = [[nsuserdefaults alloc] initwithsuitename:@"group.yourcompany.todayextensionsharingdefaults"];  [shareddefaults setinteger:[self.textfield.text integervalue] forkey:@"mynumberkey"]; [shareddefaults synchronize];   // (!!) crucial. 

swift

let appgroupid = "group.yourcompany.todayextensionsharingdefaults" let defaults = nsuserdefaults(suitename: appgroupid)  defaults.setinteger(1, forkey: "mynumberkey") 

step 5.

objective c

 nsuserdefaults *defaults = [[nsuserdefaults alloc] initwithsuitename:@"group.todayextensionsharingdefaults"];     nsstring* colornumber= [defaults objectforkey:@"mynumberkey"]; 

swift

let appgroupid = "group.yourcompany.todayextensionsharingdefaults" let defaults = nsuserdefaults(suitename: appgroupid) let number = defaults.integerforkey("mynumberkey") 

step 6. last not list don't forgot enable "allow full access" enable. goto keyboard -> info.plist -> nsextention -> nsextensionattributes

enter image description here can solve problem.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -