URL for ALAssets are all the same - iphone

I print out a number of ALAssets and they all have the name public.someFileType
Added asset ALAsset - Type:Photo, URLs:{
"public.jpeg" = "assets-library://asset/asset.JPG?id=1000000020&ext=JPG";
}
Is that something I need to be concerned about or should I just focus on
"//asset/asset.JPG?id=1000000020&ext=JPG";
IS there an easy way of getting the filename of the Asset. I asked a similar question and I got a great answer but it seems overkill.

Yes the URL is really the "//asset/asset.JPG?id=1000000020&ext=JPG" part. There is no way to get the real filename that is officially supported by Apple.

Related

Pass NSDictionary or a String from one App to another App iPhone

I have to send data which is present in an dictionary from one application to another application, which has to used over there.
Please help.
I am not exactly sure about how to do it but I think you might need to use the Custom URL Schemes for that. Here is a link that can help you register your URL Scheme and then using it.
At least you can pass it as a string parameter of custom url (like thesecondapp://data_string_goes_here) and then parse it from within the app you pass it to
See how to encode NSData to NSString here.
EDIT: You should also take a look at application:openURL:sourceApplication:annotation: method implementation examples. It could be a bit more sophisticated but it seems to be more 'native' than just passing a raw string.
Here is the info how to call the 'counterpart' of this method from another app.

iOS basic FTP setup; Read and Write Stream

I'm attempting to create an iOS 5 app with some very basic FTP functionality and need some guidance. It will be connecting to a device on a local network and performing read/write actions with .dat/txt files. I've done some searching for the past few days and have seen various recommendations but nothing simple enough that I can pick up and quickly modify for my personal use.
My questions are these:
Are there any tutorials/sample code that you could recommend to me?
What frameworks and classes should I be working with for basic read/write operations?
Lastly, I should mention that I have given a considerable amount of time to analyzing the SimpleFTPSample from Apple but the sample code is giving "Connection Failure" and "Stream Open Error" notices for each example, so I'm a bit wary of its usefulness.
Forgive me if this has been answered elsewhere. All of the related posts have pieces of the answer I need, but not the whole thing. Thank you in advance!
EDIT for clarity: A well-defined example or step-by-step tutorial is what I would really like. My own Google searches have turned up nothing and I am desperately in need of some guidance here.
UPDATE:
I posted this question long ago but have continued using the FTPHelper mentioned in the accepted answer. I recently brushed the dust off the old project and realized there was a minor memory leak in FTPHelper's fetch function that can be an app-killer if called repeatedly. If anybdy stumbles across this question and chooses to use FTPHelper, be sure to add the CFRelease line seen in the code below.
- (void) fetch: (NSString *) anItem
{
if (!self.uname || !self.pword) COMPLAIN_AND_BAIL(#"Please set user name and password first");
if (!self.urlString) COMPLAIN_AND_BAIL(#"Please set URL string first");
NSString *ftpRequest = [NSString stringWithFormat:#"%#/%#", self.urlString, [anItem stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
/* CFShow(ftpRequest); */
NSString *writepath = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents"];
self.filePath = [writepath stringByAppendingPathComponent:anItem];
CFURLRef writeURL = CFURLCreateFromFileSystemRepresentation (NULL, (const UInt8 *) [writepath UTF8String], [writepath length], NO);
MySimpleDownload((CFStringRef)ftpRequest, writeURL, (CFStringRef) self.uname, (CFStringRef)self.pword);
CFRelease(writeURL);//ADD THIS LINE TO FIX MEMORY LEAK
}
The SimpleFTPSample app is running perfect, probably there is an issue that you can't see. What I can recommend you (except Apple's example) is to check THIS example which contains a helper class for all basic FTP operations. One thing to be aware of is iOS 5 ARC. Both Apple's example and the one I linked are for older iOS versions.
There are basically 2 ways to use them in iOS 5 - by telling the compiler to not use ARC by adding -fno-objc-arc flag in [Your project] -> TARGETS -> [Your app] -> Build Phases -> Compile Sources -> [Your file], or by using the built-in tool in Xcode for converting to ARC.
I personally have tested only the first method and it works for me.
If this does not help you I can write an example, but unfortunately today I am very busy.
UPDATED:
The basic mechanism is to use [FTPHelper list:THE_FTP_URL] to list the content of a folder, then create one list with the content and depending on the type (file or folder) download using [FTPHelper download: THE_FTP_URL_WITH_THE_FILENAME_FROM_LISTING]. From here you have to implement
- (void) downloadFinished
{
//do the reading depending on the file type
NSData *data = [NSData dataWithContentsOfFile:[FTPHelper sharedInstance].filePath];
}
The uploading is achieved in a similar way - using [FTPHelper upload:FILE_TO_UPLOAD] with a file from the filesystem.
There are many libraries which you could use and they are working great. :)
For example:
http://www.chilkatsoft.com/ftp-objc.asp
http://code.google.com/p/ios-ftp-server/
I recommend using them, because coding one by yourself would take a lot of time :)
One thing to remember, as o15a3d4l11s2 said, is to be aware of ARC. If you use it don't forget to add build flags to libraries which aren't ARC.

How to save UIWebView content as .webarchive format?

I had been tried this library: https://github.com/stake/STWebArchiver
It's good, but if I access some web pages isn't well-formed, it would not be saved.
So, is there any way for me to try to save web page(s) as .webarchive on iOS devices?
Could somebody give me some advices?
Thanks a lot!
You cannot. UIWebView is not equal to the WebView class in Mac OS X. I recommend you try ASIWebPageRequest.
For Webpage not well formatted, the libxml parser(which is the original STWebArchiver using) is not a good solution. So I update STWebArchiver with Regular Expression
like this
NSArray *pathsForImagesAndScripts = [self extractResourcesWithHTML:htmlContent regex:#"<(?:script|img).*src=[\"']((?!data:).*?)[\"']"];
checkout: this

Iphone - Writing a media player with lyrics

I want to write a simple media player which displays lyrics that are retrieved from the web.
I know once LyricWiki was such a source, but now no longer exists.
Does a new API or source for lyrics exist that I can use ?
When I do get the lyrics, how do I sync them with song ?
I know the MPMediaItem class has the MPMediaItemPropertyLyrics but this is cleary not enough for me cause this is only for songs from Itunes and not all of them have lyrics available.
I would appreciate any help or links that can I use to sort this issue.
A little Googling and I found a few options that might solve your problem:
First, LyricWiki does still exist. It's moved to lyrics.wikia.com. It seems that their API, however crops the lyrics, due to licensing.
LyricsFly
ChartLyrics. Looks the most promising to me, though I haven't actually tried any of the services myself (yet).
I'd like to hear which works for you the best, should any of them.
https://developer.musixmatch.com
it's an Official and Authorized lyrics api
The synced lyrics api are expensive. following do the job but dont know how expensive they are.
http://www.lyricfind.com
http://developer.echonest.com/sandbox/lyricfind.html

How can I query chapter metadata from a m4a file?

I need to write some code that will let me query a m4a file and extract the chapter information out. Including:
chapter name
chapter start time
chapter artwork
I did some quick searching and it seems this is viewed as proprietary information by Apple? I found some discussions, but most were from 2005. Also there have been some similar questions on here, but more for CREATING m4a files with chapters, not querying.
Is this just something I have to DIY, cause there isn't a nice apple API for me to use? Or am I missing something obvious?
Also, ideally I need whatever technique I end up using to work on the iPhone.
The metadata tags system is Apple-proprietary. To work with the tags, you have to (sigh) reverse-engineer it or work with a library that has already done this.
I found the following links, but honestly it seems like you will have to pull out the hex editor.
Binary format info (basic spec for generic tags)
Perl library for working with M4A files.
Turns out this is much simpler than talked about here in the "answers". Not sure if this works on the iPhone, but I just tested it in a command line app:
QTMovie* movie = [QTMovie movieWithFile:#"filename.m4a" error:nil];
NSInteger numChapters = [movie chapterCount];
NSLog(#"Number of Chapters: %d", numChapters);
NSArray* chapterArray = [movie chapters];
for ( NSDictionary* chapDict in chapterArray )
{
NSLog(#"%#", [chapDict objectForKey:#"QTMovieChapterName"] );
}
Easy as pie. DOH!
this library should solve your needs, but is not runnable on iphone without jailbreaking I would think. http://wmptagext.sourceforge.net/
oops if you need it to work on iphone there is probably an apple api to get this info. /me looks
it sounds like you need to play around with the ipodlibrary library....
http://developer.apple.com/iphone/library/documentation/Audio/Conceptual/iPodLibraryAccess_Guide/UsingTheiPodLibrary/UsingTheiPodLibrary.html#//apple_ref/doc/uid/TP40008765-CH101-SW1
If the files in question live in the iPod library,
maybe you can get your information via the MPMediaLibrary
query interface (3.0 upward).