MPMusicPlayerController and setNowPlayingItem - iphone

I'm using MPMusicPlayerController, specifically with setNowPlayingItem protocol and it's for cydia. But I have some issues and theos' warning when i make. It seems that some of the protocols and methods are not working and I receive some warning like this:
Tweak.xm:177: warning: ‘MPMusicPlayerController’ may not respond to ‘-skipToPreviousItem’
Tweak.xm:188: warning: ‘MPMusicPlayerController’ may not respond to ‘-pause’
Tweak.xm:193: warning: ‘MPMusicPlayerController’ may not respond to ‘-play’
Tweak.xm:201: warning: ‘MPMusicPlayerController’ may not respond to ‘-skipToNextItem’
Tweak.xm:317: warning: ‘MPMusicPlayerController’ may not respond to ‘-setNowPlayingItem:’
Have anyone some ideas? I enter the protocol already in prototype

I don't think it's because of cydia - it sounds like a compilation issue.
Have you definitely got
#import <MediaPlayer/MediaPlayer.h>
in your file?

have you added the MediaPlayer.framework to your project?
select your project in the project navigator
select your target on the right side
select the "Build Phases" tab
open "Link Binary With Libraries"
add your framework

I'm using MPMusicPlayerController, specifically with setNowPlayingItem. This is a complete online verses asset with an immense assortment of melody verses, data, what's more, MPMusicPlayerController *mp = [MPMusicPlayerController. downloadmp3music

Related

Issue with Duplicate symbol in link phase of project build in Xcode

I've been building a game application for iOS. The application was working fairly well, but I've done a fairly large restructure today to be a little more model-view-controller 'compliant'.
I've built the main game engine in C++, but use Objective-C for managing the viewControllers, views etc.
Now, when I compile the project, I'm getting an error in the link phase. Details are below:
ld: duplicate symbol ApplicationEngine::OnFingerUp(Vector2) in /Users/Dan/Library/Developer/Xcode/DerivedData/BlackHoles-exrlidtstxzdtsbyjghgquhlsqul/Build/Intermediates/BlackHoles.build/Debug-iphonesimulator/BlackHoles.build/Objects-normal/i386/ApplicationEngine.o and /Users/Dan/Library/Developer/Xcode/DerivedData/BlackHoles-exrlidtstxzdtsbyjghgquhlsqul/Build/Intermediates/BlackHoles.build/Debug-iphonesimulator/BlackHoles.build/Objects-normal/i386/AppDelegate.o for architecture i386
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/g++-4.2 failed with exit code 1
OnFingerUp is a function within my C++ ApplicationEngine, and gets called from the viewController.
Is the problem likely to be caused by some confusion in my #includes / #imports?
My AppDelegate file needs to #include a MainViewController file to set up the initial viewController. The MainViewController in turn #includes the ApplicationEngine file to instantiate that class. ApplicationEngine contains the OnFingerUp method. The OnFingerUp method is then called from MainViewController when I get a touch input. Could this sequence of includes be causing the duplicate?
I've noticed that if I temporarily remove the OnFingerUp method from the app completely, then I get the same issue with another method within the ApplicationEngine.
There aren't any errors or warnings as the individual files compile. I've also tried to Clean All and recompile, but no joy.
Does anyone have any suggestions as to how I could approach solving the issue? Thanks, Dan.
I can think of 3 causes for this: 1) Accidentally #including a .cpp file, 2) forgetting #ifndef guards in the header file, 3) forgetting inline when writing the method definition in a header file.

Referencing Classes from Different Targets in xCode for iPhone Unit Testing

I am trying to unit test my iPhone application. I have created a new target and called it "LogicTests". But now I need to use a class called "Spaceship" inside the test. How can I do that?
UPDATE 1:
I made the Spaceship.m available to the unit testing target and that particular error was gone. Now I have different problem. The Spaceship.m file reference to the Cocos2d library. How can I add a reference to the Cocos2d library in the unit testing target. I tried right clicking the Link binary with libraries option and then adding the cocos2d framework but it gave me 153 errors or something.
To include it in that target, click on Spaceship.m, get the file's Info (Command-I), and make sure "LogicTests" is checked under the Target tab.
Beyond that, make sure you add
#import "Spaceship.h"
To the top of the particular test class. Good luck!
In Xcode 4 you press: Alt-Command-1 and then check that "LogicTests" is checked under the Target Membership tab.

Core-Plot: Unknown class CPLayerHostingView in Interface Builder file

Using core-plot does not seem to be an easy integration task. Header path are already setup. In Interface-Builder I create an CPLayerHostingView which belongs to a View Controller which is instantiated by Interface Builder.
When the nib file is loaded I get the message:
Unknown class CPLayerHostingView in Interface Builder file
I found, that there are two different versions of that object. One for Mac-Only called "CPLayerHostingView", one for iPhone only called "CPGraphHostingView".
If following the poplular example at http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application you would use the following lines, if building an iPhone-App:
CPGraphHostingView *graphView = (CPGraphHostingView*)self.view;
graphView.hostedGraph = graph;
http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application
Here is the answer ..
U can see mars' answer there
"i got it to work....ok, i added the -all_load -ObjC flag in the Target>Settings....I think this is where everyone gets confused...There are 2 places where to put the other link and header search paths, in Project Settings and in Target Settings.."
So solution is
Add -all_load -ObjC in Project settings and target settings
I had to rename CPLayerHostingView to CPGraphHostingView to get this to work after upgrading to the latest version of core plot (along with iOS 4 and the upgrade of XCode).
I think you're saying that you get this error when you load the NIB file in your app's code. In that case, the error suggests that you haven't built the Core Plot classes into your application (iPhone) or linked against the CorePlot framework and copied into the app bundle's Frameworks/ directory (OS X).
CPGraphHostingView
thank u it worked for me aswell;
3 imp things
1>perform settings for both project target aswell as application target.(make sure configuration is all configuration)
2>give correct header search path for framework library
3>learn over it::::::-)
For whatever it is worth.
Followed tutorial: http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application and ended up having that same error. I looked into the CorePlot framework folder and did not find that CPLayerHostingView there, but found CPGraphHostingView inside iPhoneOnly folder.
Changed CPLayerHostingView to CPGraphHostingView in IB and error disappeared.
So, check what is in yours and use it. May work.

Calling method on category included from iPhone static library causes NSInvalidArgumentException

I have created a static library to house some of my code like categories.
I have a category for UIViews in "UIView-Extensions.h" named Extensions.
In this category I have a method called:
- (void)fadeOutWithDelay:(CGFloat)delay duration:(CGFloat)duration;
Calling this method works fine on the simulator on Debug configuration.
However, if try to run the app on the device I get a NSInvalidArgumentException:
[UIView fadeOutWithDelay:duration:]: unrecognized selector sent to instance 0x1912b0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIView fadeOutWithDelay:duration:]: unrecognized selector sent to instance 0x1912b0
It seems for some reason UIView-Extensions.h is not being included in the device builds.
What I have checked/tried
I did try to include another category for NSString, and had the same issue.
Other files, like whole classes and functions work fine. It is an issue that only happens with categories.
I did a clean all targets, which did not fix the problem.
I checked the static library project, the categories are included in the target's "copy headers" and "compile sources" groups.
The static library is included in the main projects "link binary with library" group.
Another project I have added the static library to works just fine.
I deleted and re-added the static library with no luck
-ObjC linker flag is set
Any ideas?
nm output
libFJSCodeDebug.a(UIView-Extensions.o):
000004d4 t -[UIView(Extensions) changeColor:withDelay:duration:]
00000000 t -[UIView(Extensions) fadeInWithDelay:duration:]
000000dc t -[UIView(Extensions) fadeOutWithDelay:duration:]
00000abc t -[UIView(Extensions) firstResponder]
000006b0 t -[UIView(Extensions) hasSubviewOfClass:]
00000870 t -[UIView(Extensions) hasSubviewOfClass:thatContainsPoint:]
000005cc t -[UIView(Extensions) rotate:]
000002d8 t -[UIView(Extensions) shrinkToSize:withDelay:duration:]
000001b8 t -[UIView(Extensions) translateToFrame:delay:duration:]
U _CGAffineTransformRotate
000004a8 t _CGPointMake
U _CGRectContainsPoint
U _NSLog
U _OBJC_CLASS_$_UIColor
U _OBJC_CLASS_$_UIView
U ___CFConstantStringClassReference
U ___addsf3vfp
U ___divdf3vfp
U ___divsf3vfp
U ___extendsfdf2vfp
U ___muldf3vfp
U ___truncdfsf2vfp
U _objc_enumerationMutation
U _objc_msgSend
U _objc_msgSend_stret
U dyld_stub_binding_helper
The only solution that worked was to include:
"-all_load"
in other linker flags.
EDIT: Be sure to add this flag to the project including the static library, not to the static library itself.
I know this isn't the correct method, but it is working for now.
It maybe a OS 3.0 issue since this was the work around for Three20 as well.
Unfortunately, due to the what categories work and the dynamic nature of the Objective-C runtime, not everything works well with static libraries. The reason you get this error is that the category implementation in the static library is never actually linked into the executable image because the compiler has no way of knowing that the implementation code will be needed at run-time.
In order to cure this, you can force the linker to copy object files from a static archive for any and all Objective-C Class and Category images. The downside is that your executable will include image code for classes that you may not be using at all. To get the linker to include the category code, add -ObjC to the OTHER_LD_FLAGS build setting in Xcode. Your category implementation will now be copied from the static archive to your executable and you won't get the runtime exception.
I just spoke to an Apple engineer about this, and this has been addressed in ld with versions >100. This is included in Xcode 4. He walked me through this and I tried it myself and indeed the category problem is fixed.
Take out "-all_load" and go back to "-ObjC" in your Build Settings with the new linker.
If you are on Xcode 3.2 you can avoid using -all_load and instead use -force_load for just the library in question, which should be slightly more efficient.
This is described in a recently updated Apple Technical QA: http://developer.apple.com/mac/library/qa/qa2006/qa1490.html
The issue that -all_load or -force_load linker flags were needed to link categories has been fixed in LLVM. The fix ships as part of LLVM 2.9 The first Xcode version to contain the fix is Xcode 4.2 shipping with LLVM 3.0. The mentioned fixes are no longer needed when working with Xcode 4.2. The -ObjC flag is still needed when linking ObjC binaries
I ran into this problem recently. I was unable to get the -all_load to work, when I noticed that another category I had DID work. I was lazy for this category and included it in with another file.
I eventually created a dummy class (no methods, instance variables) and included the implementation of my categories in the .m file for that dummy class. After doing this my categories started working even after I removed the -all_load flag.
This was on iPhone OS 3.1.3.
This certainly is not the RIGHT way to fix it, but it seemed to work.
Full sample code is on my blog for my (trivial) categories.
I just had this same problem but adding any combination of the described flags (-ObjC, -all_load, -force_load) did not work.
It turned out that I had not checked the box "Add to Target" when adding the files to the project. I removed the files from the project and added them again, this time making sure that that box was checked. This fixed the problem.
In the past I was able to force linkage of the category with -u .objc_category_name_UIView_Extensions, but with the 3.0 dev environment that's broken and the only option seems to be -all_load.
I had the same problem with Categories in my static library. In my case, "-all_load" didn't help as it caused loads of build errors (my static library is a wrapper around another private C/C++ lib).
I solved it by a hack suggested at http://iphonedevelopmentexperiences.blogspot.com/2010/03/categories-in-static-library.html which simply involved adding a dummy (empty) class definition to the category files. Using this hack, I kept "-ObjC" but dropped "-all_load" in the application linker settings and it worked fine on the device.

Issue in including AVAudioPlayer

I'm trying to use this class as
AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL error: nil];
And getting this compiler error
error: AVAudioPlayer.h no such file or directory
I have added #import "AVAudioPlayer.h at the beginning of the .m file
Could you let me know how can I fix it?
Thanks
Instead of
#import "AVAudioPlayer.h"
Try
#import <AVFoundation/AVAudioPlayer.h>
Add the AVFoundation framework to your project.
The problem is in the fact that as the Fistman said, you probably did not add the Framework to your project.
You need to go to the Frameworks folder (in your project tree on the left side, usually just bellow the Resources folder), right click on Frameworks->Add->Existing Frameworks..' and pick AVFoundation from the list.
Notice that by default XCode will open the frameworks folder of your set Active SDK and so it must be at least OS 2.2 in order to show up (that's the earliest version when apple released it).
Once you added the framework, it should compile and link and you wouldn't have to add the h files manually.
Hope it helped,
-Adi