ios - Passing UIImage from iPhone to Apple Watch results in nil response in watch -
my watch needs request image containing app. in watch's controller, have:
- (void)getorglogo { nsstring *host = mfainfo[@"host"]; nsdictionary *getorglogorequest = @{@"request":@"getorglogo", @"host":host}; [myinterfacecontroller openparentapplication:getorglogorequest reply:^(nsdictionary *replyinfo, nserror *error) { if (error) { ... } else if (replyinfo == nil) { // getting block!!! } else { uiimage *orglogo = replyinfo[@"orglogo"]; if (orglogo != nil) { [self.orglogoimageview setimage:orglogo]; } } }]; }
in main app, send request server image, pass image watch:
- (void)application:(uiapplication *)application handlewatchkitextensionrequest:(nsdictionary *)userinfo reply:(void (^)(nsdictionary *))reply { ... if ([[userinfo objectforkey:@"request"] isequaltostring:@"getorglogo"]) { nsstring *host = userinfo[@"host"]; [self handlewatchkitgetorglogorequest:reply withhost:host]; } ... } - (void)handlewatchkitgetorglogorequest:(void (^)(nsdictionary *))reply withhost:(nsstring *)host{ nsmutabledictionary *response = [[nsmutabledictionary alloc] init]; // server request image [oktaapiclient getlogourlfromhost:host withsuccess:^(uiimage *image) { // i'm getting in here - indicating got image response[@"orglogo"] = image; // double checked value of response here - it's not nil! reply(response); } withfailure:^(uiimage *image) { ... reply(response); }]; }
as commented in code above, checked value of response right before pass watch , confirmed contain value (a uiimage), in callback of watch code, reply becomes nil. not know happens in process. thoughts?
another way enable app groups , save images shared folder. if saving multiple images.
start enabling app groups under capabilities tab both iphone , apple watch target.
then use code on iphone save image.
[oktaapiclient getlogourlfromhost:host withsuccess:^(uiimage *image) { nsurl *groupurl = [[nsfilemanager defaultmanager] containerurlforsecurityapplicationgroupidentifier:@"group.az.simplesudoku"]; nsstring *sharedfilepath = [groupurl.path stringbyappendingformat:@"/%@", @"logo.png"]; [uiimagepngrepresentation(image) writetofile:sharedfilepath atomically:yes]; reply(response); } withfailure:^(uiimage *image) { ... reply(response); }];
and load image on watch.
nsurl *groupurl = [[nsfilemanager defaultmanager] containerurlforsecurityapplicationgroupidentifier:@"group.az.simplesudoku"]; nsstring *sharedfilepath = [groupurl.path stringbyappendingformat:@"/%@", @"logo.png"]; nsdata *imgdata = [nsdata datawithcontentsoffile:imagefilepath]; [myinterfaceimage setimagedata:imgdata];
as long app groups set correctly, works well. use pass sudoku board images , forth in app.
Comments
Post a Comment