I'm looking for cocoa framework that acquires the following information for each application : vendor name, version and full application name.
Alternatively, I could use a file that contain this information ... I've tried to search it in /Application/(name).app/... but I couldn't find it in specific location that is the same for all applications.
It should be in the info.plist under CFBundleName
If you go into <application>/contents/info.plist you'll find it there
from the documentation:
CFBundleName (String - iOS, OS X) identifies the short name of the
bundle. This name should be less than 16 characters long and be
suitable for displaying in the menu bar and the app’s Info window. You
can include this key in the InfoPlist.strings file of an appropriate
.lproj subdirectory to provide localized values for it. If you
localize this key, you should also include the key
CFBundleDisplayName.
here's an example code for acquiring version from Info.plist of a selected application:
string GetAppVersion(string app)
{
NSString *vlcFilePath = [NSString stringWithCString:app.c_str()];
NSDictionary* infoDict = [[NSBundle bundleWithPath:vlcFilePath] infoDictionary];
NSString* version = [infoDict objectForKey:#"CFBundleVersion"];
}
...
...
GetAppVersion("/Applications/Notes.app").c_str());
Related
I'm using the following code snippet in a Mac Catalyst app to "export" (copy) a file from an URL to a user-selected URL:
UIDocumentPickerViewController* documentPicker = [[UIDocumentPickerViewController alloc] initForExportingURLs:#[ [[NSURL alloc] initFileURLWithPath:path] ] asCopy:YES];
This works as expected if a local folder is picked (the file in path is copied there). However, if a network folder is picked (in this case, SMB), a zero-length file is generated and no error is shown.
Does anyone know what might cause this?
I want to detect at runtime of my Mac application (written in Objective-C) if the user's Mac is joined to an Active Directory Server or Open Directory Server and/or any sort of "network account server". And to read the string of that setting if it exists. That is, the the setting from the Login Options pane of the "Users & Groups" applet in Systems Preference. See picture below.
Specifically, just reading the string of the specified server would be sufficient.
What's API set should I be looking at to read this setting?
A computer can be bound to multiple network account servers at one time. To list them you could use the OpenDirectory framework by creating an ODSession and list all registered nodes.
#import <OpenDirectory/OpenDirectory.h>
...
ODSession *mySession = [ODSession defaultSession];
NSError *err;
NSArray *nodeNames = [mySession nodeNamesAndReturnError:&err];
NSLog(#"nodeNames=%#", nodeNames);
I'm bound to Mac-mini.local OpenDirectory Server, and that outputs this:
nodeNames=(
"/Contacts",
"/LDAPv3/Mac-mini.local",
"/Local/Default",
"/Search"
)
To get further information about a registered node, just create an ODNode instance from the node name in the nodeNames array and use that to query that node.
ODNode *node = [[ODNode alloc] initWithSession:mySession name:#"/LDAPv3/Mac-mini.local" error:&err];
Or, you could also create an ODNode instance of a top node, like the /LDAPv3 node, directly and just ask for it's subnodes, like this:
ODNode *node = [[ODNode alloc] initWithSession:mySession name:#"/LDAPv3" error:&error];
NSArray *subnodes = [node subnodeNamesAndReturnError:&err];
NSLog(#"subnodes=%#", subnodes);
That gave me this output:
subnodes=(
"/LDAPv3/Mac-mini.local"
)
Note: there is also -unreachableSubnodeNamesAndReturnError:
If you need more info about this framework, the documentation can be found here
in my app, I want to load certain image user picks, make some modification, after that, save a copy in my own file format. Since I want to keep track of user modification, I decided to export my file as a package(bundle).
So, in my document class, there's a NSImage object that holds the image file. In the fileWrapperOfType:error: method, I've setup a NSFileWrapper object, and put the object in it. Here's the code:
NSDictionary *fileWrappers = [self.documentFileWrapper fileWrappers];
if (image != nil) {
NSBitmapImageRep *imageRep = [image bitmapImageRepresentation];
NSData *imageData = [imageRep representationUsingType:NSPNGFileType properties:nil];
NSFileWrapper *imageFileWrapper = [[NSFileWrapper alloc]
initRegularFileWithContents:imageData];
[imageFileWrapper setPreferredFilename:#"image"];
[[self documentFileWrapper] addFileWrapper:imageFileWrapper];
}
return self.documentFileWrapper;
In my project plist file, I have two document types, first is the type of public.image since I need to load images in my app:
The other one is my own document type. To make the file a package, I've checked the bundle checkbox in xcode:
If I simply run this now, the code compains that finding extension from type identifier is deprecated, so, I managed to add an entry in Exported UTIs:
At this moment, everything seems working, except that the outputed folder with mdc extension, is indeed a folder instead of a package, what am I missing here? Thanks in advance!
Finally I solved the problem, the key here is to change Conforms To field to com.apple.package.
In order for a package on OS X to be a pkg, it must have a .pkg extension. I hope it is as simple as having the wrong extension.
Note: Until recently, .pkg files were merely directories. Now, we often see package.pkg packages that are obscured cannot be browsed causually without some tricks like using Pacifist, pkgutil or xar:
pkgutil --extract file.pkg folder/
or
xar -xf file.pkg
I would like to get the unique identifier of my application that is used as the file name in the IOS file system. How to do that ?
If you are talking about path to your app which contains uniq. identificator then you can extract this id from path of main bundle [[NSBundle mainBundle] bundlePath].
I have finished the majority of my application that I am working on, but I have run into a problem. Basically, what I wrote streams audio from my server to the iPod and plays it without having to save the file. It has a GUI that allows the user to choose the file they want to listen to, and it works flawlessly.
My problem is that I want to be able to have some sort of a counter that updates every time a user listens to a file. I have a file in the project, "TotalDownloads.txt," that I had planned on using to store the new value and upload back to the server, but when the code executes, nothing changes within that file. I had also tried just declaring the file #"TotalDownloads.txt," but that created a new file in the Macintosh HD named "TotalDownloads.txt."
The two identifiers "//-" and "-//" are to parse the file for the number, when I get this figured out, specifically to isolate the numeric value, should there be any formatting involved. Eventually, I want to have counts for each and every one of the files.
I have no problem with downloading the text file off of the server and reading it into the iPhone, but the problem arises when sending it back. What is the easiest way to 1, make a temporary file text file on the iPhone, and 2, upload it back to the server to replace the existing file?
Is there a way to just modify the file on the server?
Any help is appreciated.
Below is what I have so far:
- (IBAction)action
{
NSURL *textURL = [NSURL URLWithString:#"http://www.faithlifefellowship.us/Audio/TotalDownloads.txt"];
NSString *textFromFile = [NSString stringWithContentsOfURL:textURL encoding:NSUTF8StringEncoding error:false];
int click = [textFromFile intValue];
click += 1;
NSString *replace = #"//-";
NSString *clicks = [NSString stringWithFormat:#"%d",click];
replace = [replace stringByAppendingString:clicks];
replace = [replace stringByAppendingString:#"-//"];
//test is a label I used to check to make sure the download count was being read properly.
test.text = clicks;
[replace writeToFile:[[NSBundle mainBundle] pathForResource:#"TotalDownloads" ofType:#"txt"]atomically:YES encoding:NSUTF8StringEncoding error:NULL];
}
Here is the best way I suggest you do this.
Set up a page on your server that accepts a get request.
Code the page to take the value from that get request (which should be the name of the file you are trying to update) and update the file at that path.
From your app, use UIWebView this way:
UIWebView* web = [UIWebView new];
[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.mydomain.com/myPage.php"]]];
web = nil;
Presto!