Resource Directory Path Issue in iOS - ios

3.2 for developing a game.I have developed game in android but facing a problem in iOS i.e
I am facing problem to read resource images.In my game have 3 stages "Simple","Medium" and "Hard".I have put images on the following path
# "Simple/1.png","Medium/1.png","Hard/1.png"
# "Simple/2.png","Medium/2.png","Hard/2.png"
# ------------------------------------------
# ------------------------------------------
# "Simple/n.png","Medium/n.png","Hard/n.png"
In android getting correct image by using full path of image.
But in iOS it is not working.
How i can fetch image of same name from different directory in iOS.

You should probably use FileUtils::addSearchPath() and add "Simple", "Medium" or "Hard", depending on the game stage and then you can use just "1.png" to refer to the file from various Cocos2d-x APIs.

landge,
Please try this:
See my screenshot using cocos2d-x-3.6
http://prntscr.com/7zwty9
It shows Xcode with 3 files with the same name 1.png in different absolute directories: hard/medium/simple.
vector<string> searchPaths = fu->getSearchPaths();
fu->addSearchPath("res/medium");
CCLOG("fpff = %s", fu->fullPathForFilename("1.png").c_str());
This is the console output:
fpff = /Users/javier.fuchs/Library/Developer/CoreSimulator/Devices/68F9EE6B-2829-420E-9359-00EC30C6372D/data/Containers/Bundle/Application/E586FE31-AFC2-4052-9826-9B27AA75182A/MyCppGame iOS.app/res/medium/1.png
Please make sure where is the file, and take a look of the full path, inside the project.
There is no guaranty with search paths, even if you doing:
auto& list = fu->getSearchPaths();
for( const auto &item : list) {
CCLOG("%s", item.c_str());
}
You will see that adding a relative path that does not exist, the relative path will be included anyway.

Related

cordova-plugin-file: files not accessible after app update (iOS)

I am experiencing a funny problem: I am developing an ionic app, using cordova-plugin-file to store images. The resulting paths (URIs in form file:///...) are stored in a SQLite DB along with more information. When I install the app and use it, all works perfect. But if I update (or reinstall) the app, the old images are not found anymore, while newly added images work perfect.
I first suspected that the image files were being deleted on update, but I checked the content of the directory and the files are still there. (FYI: I am using file.dataDirectory/scans/ to place my files).
Then I thought that maybe I could go around the problem loading into img src a base64 blob loaded with cordova.file.readAsUrl(), but cordova.file does not find the file as well (I insist, the files are there, I checked with XCode).
So I checked further with cordova.file and it only finds files that are added after last app install, but the older files are still present in the directory.
Here my code:
private getImgSrcFromDocument(doc: Document): any {
const uri = doc.fileName;
const src = this.webView.convertFileSrc(uri);
const sanitized = this.sanitizer.bypassSecurityTrustUrl(src);
console.log({uri, src, sanitized});
return sanitized;
}
<img class="document_thumbnail" [src]="getImgSrcFromDocument(doc)">
I have already checked this, but is not my case.
By the way, the same code works perfect on Android.
Any idea what could be the problem?
Thanks in advance!
I found the reason why and the solution (very obvious when you know the problem):
Reason
On every new install, iOS renames the data directory for the app. The directory path has this form:
file:///var/mobile/Containers/Data/Application/ABC0000-1234-99DD-00FA-E835FEA/Library/NoCloud/
The hash in the middle is renewed on every install, so the stored full paths in DB are not valid anymore.
Solution
If you still can do it (no deploy yet, no real users), store only the relative path and complete it every time with this.file.dataDirectory (or wherever you wanted to store your files).
If you already have real users and want your update to 'find the files', just ignore the first part of the stored path and build it like before:
const ValidUri = this.file.dataDirectory + // The injected cordova-plugin-file
'relativeSubDirectories/' + // If you store your files in some subdirectory
this.document.storedFullPath.substr( // Take from fullPath only the filename
this.document.storedFullPath.lastIndexOf('/') + 1
);
Where storedFullPath is the string file:///var/mobile/....
After that, you still have to do the webView conversion and the sanitizing, like in the question above.
Hope this helps someone.

Xcode Projects: Is it possible to programmatically determine the path to a Library?

I have an entry like this in my pbxproj file:
146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = "<group>"; };
The part of it I'm interested is this line:
path = "../node_modules/react-native/React/React.xcodeproj";
Is there a way to modify this so I could get the path to the react-native folder programatically?
Like, if this were a bash script, I could use an expansion like so:
"$(run-some-script)/React/React.xcodeproj"
I could make a script that the user could run to automatically update the paths in the pbxproj whenever they change, but I am curious if I could have a way to have Xcode run a command to get the path to this React.xcodeproj file whenever it is opened.
Short answer is no, but you can place other source code or a library files inside the toplevel xcode project directory and then reference these files as relative paths. That way, you can link to the project relative files and then update them and the xcode build will just make use of them. For example, you can include source code that is under a completely different git repo in a subdirectory, then you can update that code differently that the toplevel source, and yet still build the whole combined project together.

How do I put custom image on 3D Sphere in ARCore

The following is my code for building a 3D Earth and showing it:
com.google.ar.sceneform.rendering.Texture.Builder builder= com.google.ar.sceneform.rendering.Texture.builder();
builder.setSource(context,R.drawable.earth);
builder.build().thenAccept(texture ->
MaterialFactory.makeOpaqueWithTexture(context, texture).
thenAccept(material -> {
earthSphereRenderable =
ShapeFactory.makeSphere(0.1f, new Vector3(0.0f, 0.0f, 0.0f), material);
Toast.makeText(context,"All done",Toast.LENGTH_SHORT).show();})
);
The Toast message is coming but I am not able to see any object. Please note that R.drawable.earth is the Earth.jpg file that I put in there, which I want to show in AR.
Here is where I am rendering it
cornerNode = new Node();
cornerNode.setParent(this);
cornerNode.setLocalPosition(localPosition);
cornerNode.setRenderable(earthSphereRenderable);
Moreover, if I replace makeOpaqueWithTexture with makeOpaqueWithColor and but color as Red then the whole thing is working fine (i.e. I can see the sphere)
What must I change here in order to be able to see the sphere with Earth's texture on it?
At this time Google Sceneform 1.8 supports 3D assets in the following formats: .obj, .glTF for which animations not supported) and .fbx with or without animations. Supported textures' formats are: .mtl, .bin, .png and .jpg.
To import a new 3D asset with textures follow these steps:
Verify that your project's app folder contains a sampledata folder. To create the folder, right-click on the app folder in the Project window, then select New > Sample Data Directory.
The sampledata folder is part of your Android Studio project, but its contents will not be included in your APK. Copy your 3D model source asset file (.obj, .fbx, or .gltf), and all of its dependencies in any of the following formats:
.mtl
.bin
.png
.jpg
into the sampledata folder.
Do not copy these source files into your project's assets or res folder, as this will cause them to be included in your APK unnecessarily. Right click the 3D model source asset and select Import Sceneform Asset to begin the import process.
The values are used by the sceneform.asset() entry in the app's build.gradle, and determine where the .sfa and .sfb – ascii and binary asset definition – files (as well as their corresponding texture files .sfm) will be generated in your project. If you're importing a model for the first time, use the default values.
Hope this helps.
Ok, I got the answer to this. It does not accept jpg files but it accepts png files. Weird stuff!

Localize iOS App name in Unity

I'm'developing a Unity3D game that shows a different (localized) app name in the iPhone's home screen according to the user local language. Note that:
I already know how to localize the iOS app name by editing the Xcode project (create a InfoPlist.string file, localize it, add the CFBundleDisplayName key to it, etc.)
I also know how automatically localize an Android app name within the Unity editor (add a values-XX.xml file with the app_name property onto Assets/Plugins/Android/res/ folder, etc.)
The question is: how can I automatically localize my iOS app name within the Unity Editor so that I don't need to perform the error-prone task 1. every time I build the project?
I think that PostprocessBuildPlayer should be the way to go, however I haven't found any documentation on how to parse it and/or modify the Xcode project file correctly to achieve this.
Long time ago I ran into trouble when I tried to modify info.plist via the Build Player Pipeline especially when doing it in Append mode. It works only once and then subsequent builds fail with "The data couldn’t be read because it isn’t in the correct format." (s. Unity forum posts like this one and my blog posting about this problem) So I decided to take the alternative way combining a customised build with an Xcode Build Pre-action.
Three steps are required:
(1) Xcode setup:
In Xcode go to Edit Scheme / Build / Pre-actions. Then click the + sign to add a New Run Script Action.
In Provide build settings select Unity-iPhone.
Paste . ${PROJECT_DIR}/modify_info_plist.sh (note the dot and blank at the beginning, is ensures that the script is executed in the caller's shell)
So it should look like this:
(2) Script modify_info_plist.sh:
Within your script you have access to all environmet variables from Xcode (s. Xcode Build Setting Reference) and you can manipulate Info.plist using the defaults command (man page). Here is a sample I used to add gyroscope to the UIRequiredDeviceCapabilities:
# Code snippet used in Unity-iPhone scheme as "Build Pre-Action"
my_domain=${PROJECT_DIR}/Info.plist
status_bar_key=UIViewControllerBasedStatusBarAppearance
logger "Start adding keys to info.plist"
defaults write $my_domain $status_bar_key -boolean NO
if [ `defaults read $my_domain UIRequiredDeviceCapabilities | grep "gyroscope" | wc -l` = "0" ]; then
defaults write $my_domain UIRequiredDeviceCapabilities -array-add "gyroscope"
fi
logger "Keys added to info.plist successfully"
(3) Build Pipeline:
Put the following code in a static editor class to create a new menu item Tools / My iOS Build with shortcut cmd+alt+b:
static string IOSBuildDir= "Develop";
[MenuItem("Tools/My iOS Build %&b")]
public static void IOSBuild () {
string[] levels = { "Assets/Scenes/Boot.unity",
"Assets/Scenes/Level-1.unity",
// ...
"Assets/Scenes/Menu.unity"
};
string path = Directory.GetCurrentDirectory ();
path += "/" + IOSBuildDir + "/Info.plist";
if (File.Exists (path)) {
Debug.Log ("Removing file " + path);
File.Delete (path);
}
BuildPipeline.BuildPlayer (levels, "Develop", BuildTarget.iPhone,
BuildOptions.AcceptExternalModificationsToPlayer);
}
I know this is no perfect solution but it's the only one I found to work stable. Two drawbacks:
Step (1) has to be repeated after major Xcode format changes
New scenes have to be appended in the editor class code in step (3)

Multiple input file tags with IOS 6+ on iPad/iPhone

EDIT :
I've been able to resolve this, after finding that iOS uploads every image as "image.jpg". In freeASPUpload.asp, I changed the following :
For Each fileItem In UploadedFiles.Items
filePath = path & fileItem.FileName
Set streamFile = Server.CreateObject("ADODB.Stream")
streamFile.Type = adTypeBinary
streamFile.Open
StreamRequest.Position=fileItem.Start
StreamRequest.CopyTo streamFile, fileItem.Length
streamFile.SaveToFile path & FileName, adSaveCreateOverWrite
streamFile.close
Set streamFile = Nothing
fileItem.Path = filePath
Next
To :
For Each fileItem In UploadedFiles.Items
FileName = GetFileName(path, fileItem.FileName)
fileItem.FileName = FileName
filePath = path & fileItem.FileName
Set streamFile = Server.CreateObject("ADODB.Stream")
streamFile.Type = adTypeBinary
streamFile.Open
StreamRequest.Position=fileItem.Start
StreamRequest.CopyTo streamFile, fileItem.Length
streamFile.SaveToFile path & FileName, adSaveCreateOverWrite
streamFile.close
Set streamFile = Nothing
fileItem.Path = filePath
Next
This is within the save function of the script. The GetFileName function iterates over what is in the folder already, and adds a number until it is unique. It then updates the file key to its new name. I've left an "image.jpg" file in the temp folder, so that it always finds one. That works for now.
What I've found, however, is for some reason, it flips the second photo out of the five that the form allows for..
I will try to fix that / look for others with the same issue. I've always had problems with iPhones and iPads rotating pictures, and it's never consistent.
I'm trying to grab multiple files from a mobile fleet of iPads and iPhones. Currently I have 5
<input type="file" name="fileX" accept="image/*">
This works fine in a browser (using free asp upload / classic ASP). In testing, it works with IOS, but only if I send one file. If I send more then one via the form, I get the error 'file not found'. It seems like the files aren't being sent at all.
The file not found kicks back when trying to manipulate the file via FSO.
Uploads here :
Dim Upload, fileName, fileSize, ks, i, fileKey
Set Upload = New FreeASPUpload
SaveFiles = ""
uploadsDirVar = "directory"
Upload.Save(uploadsDirVar)
ks = Upload.UploadedFiles.keys
Errors out here :
Set f=fs.GetFile(uploadsDirVar & "\" & Upload.UploadedFiles(fileKey).FileName)
Any ideas on how I can get around this? Everything I've read points towards the HTML5 multiple tag on a single input. However, in my scenario, this won't work. I'm also tying descriptions for the images to the fields based on field name, restricting the upload to 5, re-sizing the images on the action page before passing it to its final destination and attaching them to an email.
Any advice welcome, and thank you for your time!
**Edit
The issue seems to be that IOS names all uploads "image", coming from either the camera or the library. Now the problem is how to rename the image before the script attempts to upload it. From what I'm understanding, it needs to happen within the asp upload component before it places the file.
See the above edit for the answer. As for the flipped images - turns out they are flipped straight from the iPad. I checked the exif data and I'm not sure how to account for this in my system. If I find the answer, I'll post here.

Resources