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.
same steps , group name should same nuberwidget target keep in mind.
step 2.
step 3.
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
can solve problem.
Comments
Post a Comment