• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Trying to create an alias file by using the new NSURL methods available with Mac OS X 10.6 !
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 21:00:09 +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 =  [NSURL URLWithString:@"file:///Alias_dir/aliastext"];
       //NSURL *dest = [NSURL URLWithString:@
"file:///Alias_dir/aliastext.alias"];

       NSURL *src =  [NSURL URLWithString:Destination];
       NSURL *dest = [NSURL URLWithString:Alias];

       if (src == nil || dest == nil)
               exit(1); *// Did not exit here.*

       NSData *bookmarkData =
                 [
                 src
bookmarkDataWithOptions:NSURLBookmarkCreationSuitableForBookmarkFile
                 includingResourceValuesForKeys:nil
                 relativeToURL:nil
                 error:NULL
                 ];
       if (bookmarkData == NULL)
               exit(1);  // Did not 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
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Trying to create an alias file by using the new NSURL methods available with Mac OS X 10.6 !
      • From: Ken Thomases <email@hidden>
  • Prev by Date: Changing FirstResponder with Inputmethod
  • Next by Date: Re: Displaying a non-contentual menu & attachPopUpWithFrame
  • Previous by thread: Re: Changing FirstResponder with Inputmethod
  • Next by thread: Re: Trying to create an alias file by using the new NSURL methods available with Mac OS X 10.6 !
  • Index(es):
    • Date
    • Thread