Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7731535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:30:15+00:00 2026-06-01T06:30:15+00:00

I need to create a phonegap plugin for ios which fetches all artists from

  • 0

I need to create a phonegap plugin for ios which fetches all artists from the music library. I know how to do this in Objective C but I have no idea about javascript. I read the phongegap plugin docs for iOS but I dont understand the javascript parts. Please help.
Heres my code…

Artist.m

#import "Artist.h"
#import <MediaPlayer/MediaPlayer.h>
#import <PhoneGap/PGPlugin.h>
@implementation Artist

-(void)getArtistNames:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
    MPMediaQuery *query=[MPMediaQuery artistsQuery];
    NSArray *artists=[query collections];
    artistNames=[[NSMutableArray alloc]init];
    for(MPMediaItemCollection *collection in artists)
    {
        MPMediaItem *item=[collection representativeItem];
        [artistNames addObject:[[item valueForProperty:MPMediaItemPropertyArtist]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
    }
    uniqueNames=[[NSMutableArray alloc]init];

    for(id object in artistNames)
    {
        if(![uniqueNames containsObject:object])
        {
            [uniqueNames addObject:object];
        }
    }
    NSLog(@"%@",uniqueNames);

    PluginResult *pluginResult=[PluginResult resultWithStatus:PGCommandStatus_OK messageAsArray:uniqueNames];
    [self writeJavascript:[pluginResult toSuccessCallbackString:[arguments pop]]];

}

@end

Artist.js

var ArtistPlugin={};

ArtistPlugin.prototype.getArtistNames = function(types, success, fail)
{

          return PhoneGap.exec(success, fail, "Artist", "getArtistNames", types);
}

in index.html…

<script type="text/javascript" charset="utf-8" src="Artist.js"></script>

function onDeviceReady()
    {
        // do your thing!

        navigator.notification.alert("PhoneGap is working");
        alert('asdasd');
        var abc=Artist.getArtistNames(types, success, fail);

        alert(abc);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T06:30:16+00:00Added an answer on June 1, 2026 at 6:30 am

    A couple things:

    1. It’s best to keep the names the same between your main class in Obj-C and JavaScript. In your case that would mean that either your Obj-C class should be called ArtistPlugin or the JavaScript object you create (and it’s filename) should be called Artist. I would go with all being called ArtistPlugin. Less likely to clash.

    2. The final argument to PhoneGap.exec is an Array, so unless types is an array, it should probably look like: return PhoneGap.exec(success, fail, "Artist", "getArtistNames", [types]);

    3. Lastly, make sure you have an entry in the plugins section of your PhoneGap.plist file. The key and value would be the homogenous name you chose from step #1 (i.e.: key: ArtistPlugin, value: ArtistPlugin).

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am try to create Phonegap project in which i need to integrate ASIHTTPRequest
I need create WebView which can load a page from Youtube. I don't want
I need create clone repository. but I do not know where can I get
Need to create a custom DNS name server using C which will check against
I need to create a historical timeline starting from 1600's to the present day.
I need to create an XML schema that looks something like this: <xs:element name=wrapperElement>
I'm using Visual Studio 2008 and I need create a DataTable from a Excel
I want add new user from another script and I need create password for
I need create some fork for project. So for some beans that depends from
I need create custom dialog and put JPanel into it. Is it possible?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.