需要帮助将数组内容从PFFile转换为NSData,然后转移到app extension

时间:2016-03-21 16:11:34

标签: swift ios9 appdelegate watch-os-2

我觉得我的代码接近将NSData数组传输到Apple Watch应用扩展程序。由于Apple Watch不符合Parse协议,我需要将我的PFFiles转换为NSDatas(或UIImages),然后将它们转移。我要么做错了,要么我在错误的地方有几行代码。数据来自我的解析数据库,我知道有数据,我已经测试过了。

    query.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in

        var fileArray = [PFFile]()
        var imageArray = [NSData]()

        if error == nil && objects!.count > 0 {

            for object in objects! {

                if let message = object["imageFile"] as? PFFile {

                    fileArray.append(message)
                }
            }
        }

        for object in fileArray {
            object.getDataInBackgroundWithBlock({ (data, error) -> Void in
                imageArray.append(data!)

            })

        }
        print(fileArray)
        print(imageArray)
        replyHandler(["images":imageArray])
    })

print(fileArray)打印正确的PFFiles但print(imageArray)打印“[]”。

1 个答案:

答案 0 :(得分:1)

// popup with coordinates

			var popup = L.popup();

			function onMapClick(e) {
    		popup
        		.setLatLng(e.latlng)
        		.setContent("Koordinaten (WGS-84): " + e.latlng.lng.toFixed(8) + " E, " + e.latlng.lat.toFixed(8) + " N")
        		.openOn(map)
			}

			map.on('click', onMapClick);





// polygon			

            var POI_Alte_Baeckerei = L.polygon([
				[46.97482843, 7.43818506],
				[46.97484775, 7.43860268],
				[46.97469802, 7.43860976],
				[46.97464490, 7.43903446],
				[46.97456279, 7.43902031],
				[46.97455313, 7.43825584]
				]).addTo(map).bindPopup('Alte Bäckerei');

			var activated_on_map_detail = L.layerGroup([map_detail, POI_Alte_Baeckerei]);

			map.on('zoomend', function () {
					if (map.getZoom() >= 17.6 && map.hasLayer(activated_on_map_detail)==false) {
							map.addLayer(activated_on_map_detail);
					}
					if (map.getZoom() < 17.6 && map.hasLayer(activated_on_map_detail)) {
							map.removeLayer(activated_on_map_detail);
					}
			});

好吧,您可能会觉得imageArray打印得太频繁,并且可能经常调用replyHandler。

但是,由于在当前方法完成后异步执行块,因此无法在此方法中打印或处理结果。