ios - Sending an on-the-fly created QR Code UIImage by AirDrop fails -
i creating qr code on fly , storing uiimage. want able send using uiactivityviewcontroller somehow fails:
func generateqrcode(from string: string) -> uiimage? { let data = string.data(using: string.encoding.ascii) if let filter = cifilter(name: "ciqrcodegenerator") { filter.setvalue(data, forkey: "inputmessage") let transform = cgaffinetransform(scalex: 3, y: 3) if let output = filter.outputimage?.applying(transform) { return uiimage(ciimage: output) } } return nil }
and calling function , store uiimage:
let image = generateqrcode(from: "create code") imgqrcode.image = image
the export button uses following action:
@ibaction func sharebuttonclicked(sender: uibutton) { let objectstoshare = [imgqrcode.image!] [anyobject] let activityvc = uiactivityviewcontroller(activityitems: objectstoshare, applicationactivities: nil) activityvc.popoverpresentationcontroller?.sourceview = sender self.present(activityvc, animated: true, completion: nil) }
after choosing send via airdrop mac app crashes
2016-11-05 23:29:15.912242 ordnung[3945:888442] cgcontextscalectm: invalid context 0x0. if want see backtrace, please set cg_context_show_backtrace environmental variable.
nov 5 23:29:15 ordnung[3945] : cgcontextscalectm: invalid context 0x0. if want see backtrace, please set cg_context_show_backtrace environmental variable.
2016-11-05 23:29:15.912396 ordnung[3945:888442] cgcontexttranslatectm: invalid context 0x0. if want see backtrace, please set cg_context_show_backtrace environmental variable. nov 5 23:29:15 ordnung[3945] <error>: cgcontexttranslatectm: invalid context 0x0. if want see backtrace, please set cg_context_show_backtrace environmental variable. 2016-11-05 23:29:15.912584 ordnung[3945:888442] cgcontextconcatctm: invalid context 0x0. if want see backtrace, please set cg_context_show_backtrace environmental variable. nov 5 23:29:15 ordnung[3945] <error>: cgcontextconcatctm: invalid context 0x0. if want see backtrace, please set cg_context_show_backtrace environmental variable. 2016-11-05 23:29:15.912692 ordnung[3945:888442] cgcontextdrawimage: invalid context 0x0. if want see backtrace, please set cg_context_show_backtrace environmental variable. nov 5 23:29:15 ordnung[3945] <error>: cgcontextdrawimage: invalid context 0x0. if want see backtrace, please set cg_context_show_backtrace environmental variable. 2016-11-05 23:29:15.927580 ordnung[3945:888442] [airdrop] sender ksfoperationeventerroroccured { error = "error domain=sfoperation code=-5 \"die \u00dcbertragung ist fehlgeschlagen, da du eine ung\u00fcltige datei senden wolltest.\" userinfo={nslocalizeddescription=die \u00dcbertragung ist fehlgeschlagen, da du eine ung\u00fcltige datei senden wolltest.}"; sessionid = 76fbe80074fc; }
does have idea on how done?
cheers maik
it seems need provide image in different way, altering qr code generation way solves problem creating cgimage before creating uiimage:
func generateqrcode(from string: string) -> uiimage? { let cicontext = cicontext() let data = string.data(using: string.encoding.ascii) if let filter = cifilter(name: "ciqrcodegenerator") { filter.setvalue(data, forkey: "inputmessage") let transform = cgaffinetransform(scalex: 3, y: 3) let upscaledimage = filter.outputimage?.applying(transform) let cgimage = cicontext.createcgimage(upscaledimage!, from: upscaledimage!.extent) qrcodeimage = uiimage(cgimage: cgimage!) return qrcodeimage } return nil }
and additionally should use png or jpg representation of image:
func share() { let png = uiimagepngrepresentation(qrcodeimage) let vc = uiactivityviewcontroller(activityitems: [png!], applicationactivities: []) present(vc, animated: true) }
Comments
Post a Comment