gpt4 book ai didi

javascript - 通过应用程序级事件传递的 TIBlob 在接收端变为 NULL

转载 作者:行者123 更新时间:2023-11-30 13:20:26 26 4
gpt4 key购买 nike

我有一个非常简单的应用程序,用户可以从 iOS 照片库中选择一张图片。

传递给 Titanium.Media.openPhotoGallery.success 事件的 TIBlob 然后传递给应用程序级事件。

问题是当收到应用程序级事件时,TIBlob 为 NULL。

下面是完整的代码示例。

Titanium.UI.setBackgroundColor('#000');

var win = Ti.UI.createWindow({title: 'Camera Test', exitOnClose: true, fullscreen: true, backgroundColor: '#ffffff'});

var bt = Ti.UI.createButton({'title': 'Gallery', top: 10, width: 200, height: 50});
bt.addEventListener('click', function(e) {
Titanium.Media.openPhotoGallery({
success:function(event) {
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
alert(event.media);
Ti.App.fireEvent('uploadImage', {image: event.media, source: 'gallery'});
}else {
alert('Image was not uploaded because the type was invalid.');
}
},
cancel:function() {
},
error:function(err) {
alert('Error selecting image from gallery: ' + err);
Ti.API.error(err);
},
allowEditing: false,
autohide: true,
mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO]
});
});

Ti.App.addEventListener('uploadImage', function(e) {
alert(e.image);
alert(e.source);
});

win.add(bt);
win.open();

有什么建议吗?

最佳答案

Appcelerator 指南说通过的对象和事件必须是 JSON 序列化的 https://wiki.appcelerator.org/display/guides/Event+Handling#EventHandling-Firingevents . TiBlob 不可序列化,因此我认为该博客未能通过此次事件。

如果这真的是一个非常简单的应用程序,我建议将其更改为函数调用而不是触发事件,这样 blob 将被保留。但是,如果这绝对需要成为一个事件,您可以改为传递 event.media.nativePath,然后在您实际需要对其执行某些操作时从中读取一个 blob。

关于javascript - 通过应用程序级事件传递的 TIBlob 在接收端变为 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10386742/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com