Download and use of target dataset with Vuforia - swift

I'm downloading a specific targets.xml file and I want to access this file to use with the Vuforia SDK. The file is downloaded to the Documents Directory of the app as follow:
if fileManager.fileExists(atPath: destinationURLForFile.path){
}
else{
do {
try fileManager.moveItem(at: location, to: destinationURLForFile)
}catch{
print("An error occurred while moving file to destination url")
}
}
Now I want to access this file to use with Vuforia. I know this should be done by using STORAGE_ABSOLUTE in the load function.
// Load the data set from the app's resources location
if (!dataSet->load([dataFile cStringUsingEncoding:NSASCIIStringEncoding], Vuforia::
STORAGE_ABSOLUTE)) {
NSLog(#"ERROR: failed to load data set");
objectTracker->destroyDataSet(dataSet);
dataSet = NULL;
ret = NO;
} else {
// Activate the data set
if (objectTracker->activateDataSet(dataSet)) {
NSLog(#"INFO: successfully activated data set");
}
else {
NSLog(#"ERROR: failed to activate data set");
ret = NO;
}
}
But I get the error beneath, I named the xml file, 'targets'. Maybe you guys know something I forgot?
2017-01-31 20:12:39.262178 VidPlayback[243:5487] ERROR/AR(243)
2017-01-32 20:12:39: Failed to load dataset 'targets.xml'.
2017-01-31 20:12:39.262191 VidPlayback[243:5487] ERROR: failed to load data set
Edit: fixed it!
Used this link: https://developer.vuforia.com/forum/qcar-api/remote-dataset-ios-sdk
Change the default code in the loadAndActivateImageTrackerDataSet function:
if (!dataSet->load([dataFile cStringUsingEncoding:NSASCIIStringEncoding], Vuforia::
STORAGE_ABSOLUTE))
with this:
NSString *fullPath = [NSString stringWithFormat:#"%#/Documents/%#", NSHomeDirectory(), dataFile];
// Load the data set from the app's resources location
if (!dataSet->load([fullPath cStringUsingEncoding:NSASCIIStringEncoding], Vuforia::STORAGE_ABSOLUTE)){

Related

FileSystemException: Cannot open file, path = 'storage/emulated/0/DCIM/docs/myPdf.pdf' (OS Error: Operation not permitted, errno = 1)

I am trying to create a pdf document and write my data in that file. The data is a list of int or uint type. Able to do the same for images but not pdf or doc file. All permissions are given and it works for images. My code is below -
Future <File> createDocFile(Uint8List fileData, String type) async
{
File file = new File(".pdf");
if(await PermissionHandler.checkPermission(Permission.storage)!=true){
Url.toastShow("Storage permission not found.");
await Permission.storage.request();
}
else {
await file.writeAsBytes(fileData);
print("PDF SAVED IN DEVICE");
Url.toastShow("PDF saved in device",Colors.green);
}
}
Whenever you create a new file the device can't automatically find it. You'd have to manually tell the device to refresh for the files. Before you'd have to refresh all the files in the device for it to get updated which was very inefficient, but now you could just send the path of the file that you want to get updated. You can use the media_scanner plugin to do so.
Or If you wanna do it yourself with kotlin then here's the code,
private fun broadcastFileUpdate(path: String){
context.sendBroadcast(Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.fromFile(File(path))))
}

Failed to decompress data for the AssetBundle 'Memory'. -- Unity3D AssetBundle Loading

IEnumerator WWWLoader()
{
WWW bundleRequest = new WWW("*****************");
while(!bundleRequest.isDone)
{
yield return null;
}
AssetBundle bundle = null;
if (bundleRequest.bytesDownloaded > 0)
{
AssetBundleCreateRequest myRequest = AssetBundle.LoadFromMemoryAsync(bundleRequest.bytes);
while(!myRequest.isDone)
{
Debug.Log("loading....");
yield return null;
}
if (myRequest.assetBundle != null)
{
bundle = myRequest.assetBundle;
GameObject model = null;
if (bundle != null)
{
AssetBundleRequest newRequest = bundle.LoadAssetAsync<GameObject>("Log");
while (!newRequest.isDone)
{
Debug.Log("loading ASSET....");
yield return null;
}
model = (GameObject)newRequest.asset;
bundle.Unload(false);
}
}
else
{
Debug.LogError("COULDN'T DOWNLOAD ASSET BUNDLE FROM URL (assetBundle = null)");
}
}
else
{
Debug.LogError("COULDN'T DOWNLOAD ASSET BUNDLE FROM URL (0 bytes)");
}
}
This is my code to load an AssetBundle (I've removed the URL). It gives me the error "Failed to decompress data for the AssetBundle 'Memory'." I'm not sure if 'Memory' is referring to the AssetBundle name because mine is called 'log' so is it referring to a problem with memory? Any help on understanding this error and fixing it is much appreciated.
I believe your issue related to the compression being used when the bundles are built. You may need to use LoadFromMemoryAsync instead. https://docs.unity3d.com/ScriptReference/AssetBundle.LoadFromMemoryAsync.html
So, I have gotten past the error by using UnityWebRequestAssetBundle as shown here (recommended by derHugo).
I was initially using a simple FTP server to access the assets and it would not allow me to download them (from Unity, but in a browser it worked fine). I then switched to using a Flask server, which worked like a charm.
Note to people finding this like I did; if you're using Asset Bundles for webgl, you need to make sure the assetbundles are uncompressed (BuildAssetBundleOptions.UncompressedAssetBundle). Docs mention it but it can be easy to miss, and the default is LZMA.

Xamarin.iOS : Facing The file “” couldn’t be opened because you don’t have permission to view it. 257 issue on real iOS device

We are using "UIDocumentPickerViewController" to select the files from iOS device storage.
After that when we are trying to get the data from the file URL as below, it returns an error message. This issue I am facing only on the real iOS devices and on the iOS simulator, it working fine.
try
{
var picker = new UIDocumentPickerViewController(allowedUTIs, UIDocumentPickerMode.Open);
picker.WasCancelled += Picker_WasCancelled;
picker.DidPickDocumentAtUrls += (object s, UIDocumentPickedAtUrlsEventArgs e) =>
{
var fileUrl = e.Urls[0].AbsoluteString; // given below
NSUrl videoNSUrl = NSUrl.FromString(fileUrl);
videoNSUrl.StartAccessingSecurityScopedResource();
// videoData = NSData.FromUrl(videoNSUrl);
NSDataReadingOptions nSDataReadingOptions = new NSDataReadingOptions();
NSData videoData = NSData.FromUrl(videoNSUrl, nSDataReadingOptions, out NSError error);
Console.WriteLine(error.ToString()); // error message given below
videoNSUrl.StopAccessingSecurityScopedResource();
};
PresentViewController(picker, true, null);
}
catch (Exception ex)
{
Crashes.TrackError(ex);
}
Error message:
The file “file_example_PPT_250kB.ppt” couldn’t be opened because you don’t have permission to view it.
257
Domain "NSCocoaErrorDomain"
File path: file:///private/var/mobile/Containers/Shared/AppGroup/01DEB59C-EFF4-4E8A-A7CC-4CD3177FC8CA/File%20Provider%20Storage/Downloads/file_example_PPT_250kB.ppt
Any help and suggestions will be appreciated.
Thank you.

How to download file from dropbox using Dropbox Sync API iOS SDK

I am using Dropbox Sync API sdk it display all folder and file but we can not download file
i am using this code:
DBFilesystem *filesystem;
DBFile *file = [_filesystem openFile:info.path error:nil];
NSData *imagedata=[file readData:nil];
[fileMan createFileAtPath:Image_filePath contents:**data** attributes:nil];
NSLog(#"flao=%d",[file writeData:imagedata error:nil]);
// it return 1
I am getting NSData but i can't store in document directory.
I check below links but no success
Dropbox Sync API iOS copy files to app documents
Data syncing with DropBox API and iOS
Please Help me.
Dropbox takes time to cache a file, you can set up a block to monitor when the cache is completed:
__block MyViewController *me = self;
[self.dropboxFile addObserver:self block:^() { [me monitorDropboxFile:#"Sync"]; }];
inside the observer:
- (void)monitorDropboxFile:(NSString *)caller
{
if (self.dropboxFile.status.cached) {
; // Good to go, the file is cached
} else {
; // download in progress
}
}
Or, there is a simpler way, use readHandle:
(DBFile *)file;
// ...
DBError *dbError;
NSFileHandle *fileHandle = [file readHandle:&dbError];
As documented in the Dropbox API header:
/** Returns a read-only file handle for the file. If the file is not
cached then the method will block until the file is downloaded.
#return A file handle if the file can be read, or nil if an error
occurred. */
The file handle is ready when returned. However, you might like to put readHandle in a background thread if the app has to be responsive during file download.

Accessing GTLPlusActivity properties

I have integrated the Google Plus iOS SDK v1.2.1 into my iOS app. After authentication I am trying to fetch the user's activity feed. My code is the following:
GTLServicePlus* plusService = [[GTLServicePlus alloc] init];
[plusService setAuthorizer:[GPPSignIn sharedInstance].authentication];
plusService.retryEnabled = YES;
GTLQueryPlus *query = [GTLQueryPlus queryForActivitiesListWithUserId:#"me" collection:kGTLPlusCollectionPublic];
[plusService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLPlusActivityFeed *data,
NSError *error) {
for (GTLPlusActivity *activity in data.items) {
// ITERATE THROUGH THE ACTIVITIES
NSString *publishedDate = activity.published; <---- ERROR
// "PROPERTY 'published' CANNOT BE FOUND
// IN FORWARD CLASS OBJECT "GTLPLusActivity""
// WHY ARE THE VARIABLES SUCH AS published, placeName,
// title, actor etc NOT ACCESSIBLE
}
}];
I am able to successfully retrieve the posts of the user. The GTLPlusActivity class has many properties as shown in the image:
Whenever I try to access the properties using the "." operator such as "activity.actor" in the for loop, it gives the error "Property 'actor' cannot be found in forward class object 'GTLPlusActivity'". Why am I unable to access the properties? I need to display them in a UITableView.
EDIT: Code Snapshot. Error clearly displayed in Red.
Firstly, check the error condition and make sure the error code is nil. I have tried your code, and it works correctly on my end, so most likely, there is a problem with the response you are getting back. Generally activity.actor will return a GTLPlusActivityActor.
Try something like:
if (error) {
NSLog(#"Status: Error: %#", error);
}
else
<Do stuff>
EDIT: Also, our iOS quick-start is a great resource for seeing how we handle certain parts of the code. The ListMoments bit is pretty similar to dealing with Activities.
https://developers.google.com/+/quickstart/ios
EDIT 2: Also, make sure you have all of the right imports. Try
#import "GTLPlusActivity.h"
or
#import "GTLPlus.h"