how to keep the iphone simulator application directory be the same when run it everytime - ios-simulator

i met a problem with iphone simulator application directory, when i run the application everytime, the name of application directory was changed each of time,can anyone tell me how to keep a static application directory ?

i'm going to take a guess here and say..
you don't need a static directory.
I think what you need is to get the 'base directory' programatically.
NSString *docsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *path = [docsDirectory stringByAppendingPathComponent:#"fileName.txt"];
you should be saving your user files there (or somewhere similar)
or alternatively something like
NSBundle* bundle = [NSBundle mainBundle];
NSString* path = [bundle executablePath]
//or
NSString* path = [bundle resourcePath];
and then append your own paths onto that.
hope that helps.
NEW INFO:
If you are saving information, (a log, stats etc..) you can retrieve the files saved in the NSDocumentDirectory above using the Xcode organiser.
select your device
got the summary tab
find you application in 'Applications' section.
expand the entry and it should have an 'Applcation data' entry.
press the down arrow on the right to save your files.

If you simply relaunch the app from within the simulator springboard it will keep using the same directory. If you rebuild the app in Xcode it will move, and there is no way to prevent that. Xcode should migrate any data you have from the old directory to the new directory when it installs the new build.

I guess the problem is that XCode sometimes "loses" files.
So I lost all my preferences just now, and unable to get them back because XCode, once they are lost, can't recover them.
Here is what I did to resolve:
Open the console, note the directory it's using for the new launch, in my case that was
/Users/nik/Library/Application Support/iPhone Simulator/User/Applications/D713AFE6-D6B3-4D1E-A1B9-28FD679FD124/Documents/
Quit the app
Go to /Users/nik/Library/Application Support/iPhone Simulator/User/Applications and look for a launch that still has the preferences files in /Documents
Copy the preferences files to the last launch location above
Launch again - now it all worked. XCode created yet another temporary launch directory, but moved the files from the "last" launch over.
I am now also saving the preferences file in another location so next time this happens I have them handy.

Related

macOS Catalina + Xcode 11 Error on reading file from project

After upgrading to macOS Catalina with latest Xcode 11, I am not able to read files directly from user path when doing unit testing, example:
PROJECT_DIR + "/FolderX/myFile.json",
I keep getting error Thread 1: EXC_BAD_ACCESS (code=1, address=0x8)
This is also happened when I am trying to open a couchbase lite database with custom path.
Error:
error opening!: 14
Cannot open database, Error : Error Domain=SQLite Code=14 "unable to open database file" UserInfo={NSLocalizedDescription=unable to open database file}
I believe this is an issue due to the read write access between my simulator and the latest Catalina.
My current workaround is to add my files and database to target membership and read the files directly from [NSBundle bundleForClass:[self class]].bundlePath.
Is there any better fix to this? Like tweaking any setting to allow it to read files from custom path like in older versions?
You might try looking in SystemPreferences > Security&Privacy > Privacy tab. From there, scroll down to "Files and Folders" <-- There's where you can see programs and the folders they have been granted access to in Catalina.
Personally, I didn't have time to waste figuring out how the new file permissions are supposed to work, so I let Xcode have full disk permission. (Right above the "files and folders" is "Full Disk Access".
Of course, that solved all my issues... after I get a chance to play with the new file permissions, I may revoke that access and give it explicit folder access.
Well if anyone is still struggling with this, I've moved all my projects outside of ~/Documents/
it is strange that projects under ~/Documents/ doesnt get asked for read permission, other paths do!
I end up putting all my projects under ~/workspace/
** for those who doesnt know, ~/ means /Users/{your username}/
Check your File Access settings in the App Sandbox in your project's settings, under Signing and Capabilities. For example, I couldn't access files in /Users/Bert/Downloads, even after turning on Full Disk Access in Security and Privacy in System Preferences. I had to grant read access to the Downloads Folder in App Sandbox settings.

Converted UWP... Nothing Happens

I have converted a Win32 Application to UWP using MakeAppX and it doesn't seem to run. When I click the icon in the start menu literally nothing happens except a busy icon briefly appears on the cursor.
I completed the same process with Notepad++ and all it's DLLs and that worked fine (using the exact same manifest file, just changing the exe)
My questions are:
Where does the UWP save files that it creates/temporary files etc? If I run an executable and it generates files next to it, where would that be when you run a UWP?
Can I set that location in the AppxManifest?
Is there anyway to see if it has run correctly or not?
Edit:
Could this be a file permissions issue? My application needs to write to 'C:\MyFolder' & creates a folder with a load of files next to the executable upon startup and that doesn't happen.
So looking into this a bit more I came across this blog which discusses preparing for conversion. I think the above file accesses probably contravene the following:
Your app writes to the install directory for your app. For example, your app writes to a log file that you put in the same directory as your exe. This isn't supported, so you'll need to find another location, like the local app data store.
This looks like a fairly halting issue, am I correct in that assumption?
If your app is writing to the install directory you will need to change that code to write to your local app data folder instead, as the preparation guide calls out.
Write operations to the install directory are not allowed in order to ensure the ability for the app deployment stack to perform seamless, differential updates and clean uninstalls of your app.
Btw, to debug through your app launch failures you can do the following in Visual Studio: Debug -> Other Debug Target -> Debug Installed App Package -> select your app from the list of installed apps.

QFile path changing from build version to deploy version

I have a program that saves data inside it's own folder. This is how I save the data:
QString path = "./config/Values/"+Name+"/";
QDir *myDir = new QDir();
myDir->mkpath(path);
path += Name+"_";
path += Date+".txt";
QFile File(path);
QTextStream Out(&File);
Out.setCodec("UTF-8");
if(!File.open(QFile::WriteOnly | QFile::Text))
return;
out << data;
File.close();
Every time I run the program through QT, the saved data goes to the path: C:\Andre\Qt files\build-Pesquisa-Desktop_Qt_5_7_0_MinGW_32bit-Release\release\config\Values. I will send the full path for clarity sake.
However, I made an installer for that program. The program is installed in C:\Program Files (x86)\SOCC_Pesquisa. So the new path should be: C:\Program Files (x86)\SOCC_Pesquisa\config\Values right?
Although, when I run the program and check where the data was saved, I get this path: C:\Users\SOCC\AppData\Local\VirtualStore\Program Files (x86)\SOCC_Pesquisa\config\Values. Why does it change suddently to such a different folder?
EDIT: Via making a few tests I found out the problem is not in the installer, but in the place where it is installed. For some reason when I pass my program to C:\Program Files (x86), the data is always saved in C:\Users\SOCC\AppData\Local\VirtualStore\Program Files (x86)\SOCC_Pesquisa\config\Values. is it because of the user? or maybe admin rights?
Due to security features introduced with Windows Vista (UAC) any non-Administrator program that tries to write to protected locations such as "Program Files" will get their writes caught and redirected to an alternative "user friendly" location.
In you case C:\Users\SOCC\AppData\Local\VirtualStore\Program Files (x86)\SOCC_Pesquisa\config\Values
You can find out more about UAC here on Wikipedia
So you can move in these directions:
Run program as administrator each time.
Change directory's security settings: going properties, select the Security tab and then advanced.
Request elevation for your app as you can find on Wikipedia link.
Change the savings location to a more secure and usual, like documents or whatever you want not conflicting with UAC

How to find my realm file?

I have created a DB by realm and I am not able to find the file as my OS (Yosemite) dont have a mobile folder in the /private/var/mobile.
How should I access my realm to run in the browser?
Cross posted from google groups
Finding a Realm File
For Android
How to view my Realm file in the Realm Browser?
For iOS
If your App is on Device
Make sure that your device is connected and go to the devices window in the Xcode menu Window > Devices (⌘⇧2). There you will be able to choose your device and your app from a list of installed apps with debugging permissions.
After selecting your app, go to the cog in the toolbar at the bottom of the table view and select “Download Container…“. There you will be able to pull the file from the documents location to your Mac. It will be saved as an xcappdata bundle.
When you open the local path in Finder, where you saved it, you can tap into that by selecting “Show Package Contents” in the context menu of the finder, when you select the file. A new finder window will open, where you find your Realm inside in the following path (e.g.): AppData/Documents/default.realm (The directory '/private/var/mobile' is the path, which is used by iOS on the device filesystem.
If your App is on the Simulator
Go to your user’s directory:
/Users/<username>/Library/Developer/CoreSimulator/Devices/<simulator-uuid>/data/Containers/Data/Application/<application-uuid>/Documents/default.realm
Probably the easiest way to get the current path of the default realm is to pause the simulator and enter the following into the LLDB console:
Objective-C:
(lldb) po [RLMRealmConfiguration defaultConfiguration].fileURL
Swift using Realm Objective-C:
(lldb) po RLMRealmConfiguration.defaultConfiguration().fileURL
Swift using Realm Swift:
(lldb) po Realm.Configuration.defaultConfiguration.fileURL
Or if you have an RLMRealm instance at hand, you can use:
(lldb) po myRealm.configuration.fileURL
Then just copy this path, open your terminal, and type open [Pasted path here]
NOTE: Some paths have a space in them so be sure to use "\" before the space to escape it
Helper Tool SimPholders
This is probably the fastest way to find the file of an app in the simulator. Install SimPholders. This will allow you to access your app’s documents directory directly from your menu bar.
Note Some people have mentioned that SimPholders has taken them to the wrong simulator app folder, if that's the case for you, print out your realm path by following the steps above, printing out your realm.path
I found most simplest way for iOS/macOS
(for swift 3 Xcode 8.3)
override func viewDidLoad() {
// for swift 2.0 Xcode 7
print(Realm.Configuration.defaultConfiguration.fileURL!)
}
Then x code will log the correct path, check the screen below.
Now open your Finder and press ⌘ + ⇧ + G (command+shift+G) and paste the path that logs on your Xcode
One Easy Alternative For Simulator Apps
Create a smart folder/search in Finder. Gives quick and easy clickable access to all your realm files.
Open the folder /Users/$USER/Library/Developer/CoreSimulator/Devices in Finder.
With terminal open /Users/$USER/Library/Developer/CoreSimulator/Devices
Search for .realm
Change the search to look in the "Devices" folder only.
Save the search to your sidebar (e.g. as Realms)
When sorted by date this will give you a quick and easy clickable list of the latest modified Simulator .realm files.
Here is an easy solution.. I messed with this for awhile. I should point out, this is a specific set of instructions using Android Studio and the AVD Emulator.
1) Start the Emulator and run your app.
2) While the app is still running, open the Android Device Monitor. (its in the toolbar next to the AVD and SDK manager icons)
3) Click the File Explorer tab in the Device Monitor. There should be a lot of folders.
4) Navigate the following path: Data > Data > Your Package Name > files > Default.Realm (or whatever you named it)
Ex. If you are using one of the realm example projects, the path would be something like Data>Data>io.realm.examples.realmgridview>files>default.realm
5) Highlight the file, click the Floppy Disk icon in the upper right area "pull a file from the device"
6) Save it off to whereever you want and done.
What I did was to use
let realm = Realm(path: "/Users/me/Desktop/TestRealm.realm")
and then it gets created in full view on my desktop and I can double-click to launch the Realm Browser on it. Later, I can remove the parameter and let it use the default location when I'm satisfied that all is working as expected.
The above answers missing a way to find the realm file in Android platform and believe me this way will save your lot's of time which we generally waste in other approaches to get the realm file. So let's start...
First open "Device File Explorer" in android studio(View -> Tools Windows
-> Device File Explorer.
This will open your device explorer.
now open data -> data -> (your_app_package_name) -> files -> default.realm
default.realm is the file for which we are here. Now Save_as this file at your location and access the file from the realm_browser and you will get your database.
NOTE: Mentioned approach is tested on non-rooted phone(one+3).
Objective-C - [RLMRealmConfiguration defaultConfiguration].fileURL
NSLog(#"%#",[RLMRealmConfiguration defaultConfiguration].fileURL);
Eg-/Users/"Your-user-name"/Library/Developer/CoreSimulator/Devices/E58645FF-90DE-434D-B2EB-FA145EB6F2EA/data/Containers/Data/Application/E427BD21-2CB1-4F64-9ADF-8742FF731209/Documents/
This is the simplest command you can run to get your path to .realm file. You will see the .realm file after all your read and write operations are completed.
Or
You can you open source openSim, alternative of simpholders to access your app’s documents directory directly from your menu bar
If you are using the default Realm DB in simulator:
po Realm().configuration.fileURL
Updated answer to the newest Realm:
For Android:
checkout stetho and https://github.com/uPhyca/stetho-realm
Video tutorial here: https://www.youtube.com/watch?v=9pFJz5VexRw
For IOS (Swift)
Either:
debugPrint("Path to realm file: " + realm.configuration.fileURL!.absoluteString)
or
Step 1: Have a constant called dev somewhere. Let's say Constant file
public class Constants {
public static var dev: Bool = true
}
Step 2: Create another class called RealmFunctions.swift
import RealmSwift
func realmAndPath() -> Realm {
if Constants.dev {
// location of my desktop
let testRealmURL = NSURL(fileURLWithPath: "/Users/#####/Desktop/TestRealm.realm")
return try! Realm(fileURL: testRealmURL)
} else {
return try! Realm()
}
}
Step 3: finally in your view controller:
let realm = realmAndPath()
thanks to Stewart Lynch for the original answer
If you are getting 'Enter Encryption Key' dialog box error:
I am using Swift 2.1 with Realm 0.96.2 and was getting this error when trying to open the database file:
'default' could not be opened. It may be encrypted, or it isn't in a
compatible file format. If you know the file is encrypted, you can
manually enter its encryption key to open it.
Found that using the pre-release version of the Realm Browser 0.96 fixed the issue:
https://github.com/realm/realm-browser-osx/releases/tag/0.96-prerelease
2020: Realm file on iOS Real device (Not simulator)
Starts from the menu bar at the top then follow the sequence below: -
Window
Devices and Simulators
Select Device
At the bottom find the title (INSTALLED APPS)
Note: Scroll down or enlarge the Devices and simulators pop up window to see the list of installed apps.
Select Your app.
Tap the gear button (It's located at the bottom of the apps list)
Download Container
Choose location to save it.
Right click on the downloaded file
Show Package contents
AppData
That's it from there you can access Your Realm files depending on your configuration. For example if you saved in Documents or Library folders simply open it to see your realms.
First, I acknowledge that this is an Android thread but it is the first search result for this issue in general.
To open the most recently created Xcode Simulator Realm db in Realm Browser you can use this script in Automator or type it all in at the terminal. By using Automator, I have one-click access to my current realm.
cd ~/Library/Developer/CoreSimulator/Devices/
cd `ls -t | head -n 1`/data/Containers/Data/Application
cd `ls -t | head -n 1`/Documents
open -a 'Realm Browser' ./default.realm
Install Realm Browser.
In Automator, click New, select Run Shell Script, paste in code, change Realm Db name, Click Run to test, save file somewhere convenient for quick click access.
I don't know where I found this tip the first time but this thread reminded me how I was accessing my live data in the past.
Just for your App is on the iOS Simulator
Enter
console.log (Realm.defaultPath)
in the code eg: App.js
I have taken this one step further.
I have created a swift file called RealmFunctions and in it, I have created this function
import RealmSwift
func realmAndPath() -> Realm {
if dev {
// location of my desktop
return try! Realm(path: "/Users/slynch/Desktop/TestRealm.realm")
} else {
return try! Realm()
}
}
Now in my main view controller, I have a global boolean variable called dev
var dev: Bool = true // when in development mode
var dev: Bool = false // when I want to run on my device or upload to app stor.
Now, all I have to do in my code is
let realm = realmAndPath()
So when in development mode, I can find my realm database on my desktop and can open in Realm Browser.
I found my realm file by issuing this command in Terminal:
sudo find / -name "*.realm".
Hope this helps!
For those using React Native and using the default realm:
Realm.defaultPath
In Swift
func getFilePath() -> URL? {
let realm = try! Realm()
return realm.configuration.fileURL
}
As previously was mentioned you can use next approaches to find file location
//code
Realm.Configuration.defaultConfiguration.fileURL
//lldb
(lldb) po Realm.Configuration.defaultConfiguration.fileURL
or you can manually find it:
//Simulator
/Users/<username>/Library/Developer/CoreSimulator/Devices/<simulator-uuid>/data/Containers/Data/Application/<application-uuid>/Documents/
//for example
/Users/alex/Library/Developer/CoreSimulator/Devices/E1D084B0-CD97-41B4-871F-E131CA33F635/data/Containers/Data/Application/373721C7-2381-4E3D-9ABC-2147F748322F/Documents/
//iPhone (download a copy)
Xcode -> Window -> Devices and Simulators -> Devices -> <select device and app> -> App container actions -> Download Container... -> <selectfolder and navigate to it (.xcappdata)> -> Right Click -> Show Package Consents -> AppData -> Documents
*Please note that if you set file name for realm and it has some other extension than .realm RealmStudio does not open it by default
To get the DB path for iOS, the simplest way is to:
Launch your app in a simulator
Pause it at any time in the debugger
Go to the console (where you have (lldb)) and type: po RLMRealm.defaultRealmPath
Tada...you have the path to your realm database
The correct (lldb) command is: Realm.Configuration.defaultConfiguration.path.
If you are trying to find your realm file from real iOS device
Worked for me in Xcode 12
Steps -
In Xcode, go to Window -> Devices and Simulators
Select your device from the left side list
Select your app name under the Installed apps section
Now, highlight your app name and click on the gear icon below it
from the dropdown select the Download Container option
Select the location where you want to save the file
Right-click on the file which you just saved and select Show Package Contents
Inside the App Data folder navigate to the folder where you saved your file.
Under Tools -> Android Device Monitor
And under File Explorer. Search for the apps. And the file is under data/data.
The correct lldb command for Xcode 7, Swift 2.2+ is po Realm.Configuration.defaultConfiguration.path!
Swift 2.3 solution
Easier solution that won't break with Realm updates
let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
print("App Path: \(dirPaths)")
The .realm file should be inside "Documents"
all the steps for android and ios can be found on the official realm website:
https://support.realm.io/support/solutions/articles/36000064525-how-do-i-locate-realm-files-on-a-device-or-simulator-
Although the question itself is for iOS, the title is pretty generic as such that it got me here. So, I have felt the need to share a solution for Windows here.
In dotnet C#, use realm.Config.DatabasePath to see where the realm file is located. If not set differently, then it is C:\Users\<username>\Documents\default.realm along with default.realm.management folder and default.realm.lock
To set a new path, adapt this code (folders must exists, or gives error)
var realm = Realm.GetInstance(new RealmConfiguration(optionalPath: "C:/myproject/myrealm/myproject.realm" ));

Is there a way to change the file path for an Rstudio project?

I'm using GIT and I note that if I just move the whole folder (or rename it) in windows, that it breaks all the paths. I then end up in an infinite loop of trying to quit Rstudio and Rstudio unable to find the file path to save (or not save).
Is there a way to move the location of the project folder while keeping it still intact?
Sorry, let me make this clearer.
Start Rstudio and create a version-controlled project (I'm using GIT)
Realize that you put the project in the wrong folder of your computer
Move the project to the new folder by (a) moving the Rstudio and GIT files to another location using windows explorer. (breaking all the links) or (b) start a new project in the 'correct' location. (losing the versions of your edits).
With RStudio closed, I moved the project folder (using Windows Explorer) to a new location. My RStudio project opened fine from there. I made an edit and pushed it to Github.
If you use the here package on Cran you won't have to update any links.
If you use GitHub Desktop, it will detect that the project has been moved and allow you to locate (set) it to a different folder.

Resources