Trying to create an alias file by using the new NSURL methods available with Mac OS X 10.6 !
Trying to create an alias file by using the new NSURL methods available with Mac OS X 10.6 !
- Subject: Trying to create an alias file by using the new NSURL methods available with Mac OS X 10.6 !
- From: rohan a <email@hidden>
- Date: Wed, 13 Jan 2010 20:16:38 +0530
Hello All,
Using the new NSURL methods available with Cocoa on Mac OS X 10.6, I am trying to create an alias file to a certain file. However, this method requires a NSURL data type. But I am writing a C program along with an objective-C program to accomplish this. The C program would accept the inputs as C strings. I would then convert them to NSString and then to NSURL strings. However, this is not working :(
By hardcoding the NSURL strings the program works fine.
Below are the programs:
alias.c ===========>
/*==============================================================*/
#include<stdio.h>
#include<AvailabilityMacros.h>
int CreateAlias(char *, char *);
int main(int argc, char *argv[])
{
#ifdef MAC_OS_X_VERSION_10_6
if (CreateAlias(argv[1], argv[2]))
printf("Successful\n");
else
printf("Failed\n");
#else
printf("Cannot create Alias files\n");
#endif
return 0;
}
/*================================================================*/
createalias.m (I use the NSURL methods for creating Aliases )
/*================================================================*/
#import <Foundation/Foundation.h>
int CreateAlias(const char *target, const char *aliasname)
{
CFStringRef Ref1 = CFStringCreateWithCString(NULL, target, kCFStringEncodingASCII);
CFStringRef Ref2 = CFStringCreateWithCString(NULL, aliasname, kCFStringEncodingASCII);
if (Ref1 == NULL || Ref2 == NULL)
exit(1);
NSString *Destination = (NSString *)Ref1;
NSString *Alias = (NSString *)Ref2;
//NSURL *src = "" URLWithString:@"file:///Alias_dir/aliastext"];
//NSURL *dest = [NSURL URLWithString:@"file:///Alias_dir/aliastext.alias"];
NSURL *src = "" URLWithString:Destination];
NSURL *dest = [NSURL URLWithString:Alias];
if (src == nil || dest == nil)
exit(1);
// No exit here. NSData *bookmarkData =
[
src bookmarkDataWithOptions:NSURLBookmarkCreationSuitableForBookmarkFile
includingResourceValuesForKeys:nil
relativeToURL:nil
error:NULL
];
if (bookmarkData == NULL)
exit(1);
// No exit here.
BOOL ok = [NSURL writeBookmarkData:bookmarkData
// The program is failing here toURL:dest
options:0
error:NULL];
if (ok == NO)
return 0;
return 1;
}
/*===========================================================================*/
I also read that CFStringRef can be directly typecasted to NSString *which i have done.
Can anyone tell me what the problem may be ?
Any comments ?
Thanks
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden