I'm messing around with Rdio's iOS SDK. I've set up everything correctly in "Getting Started" outlined here (http://www.rdio.com/developers/docs/libraries/ios/). The track key in the app delegate works and plays after I launch the app.
Now I'm trying to get a simple UIButton click to play a track, and I can't for the life of me get it to work.
I have this in ViewController.h
#import <UIKit/UIKit.h>
#import <Rdio/Rdio.h>
#interface ViewController : UIViewController <RdioDelegate, RDPlayerDelegate>
#property (readonly) Rdio *rdio;
#end
And in ViewController.m
- (IBAction)playButton:(UIButton *)sender
{
[self.rdio preparePlayerWithDelegate:nil];
NSArray *sources = [NSArray arrayWithObjects:#"t1", #"p1", #"a1", nil];
[self.rdio.player playSources:sources];
}
I really appreciate the help!
I resolved my issue. My issue was I wasn't calling the initializer initWithConsumerKey... that I had in my App Delegate. I had also failed to set it as a delegate properly.
So my App Delegate looks like this:
#import "AppDelegate.h"
static AppDelegate *launchedDelegate;
#interface AppDelegate ()
#end
#implementation AppDelegate
+ (Rdio *)rdioInstance
{
return launchedDelegate.rdio;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
launchedDelegate = self;
_rdio = [[Rdio alloc] initWithConsumerKey:#"removed" andSecret:#"removed" delegate:nil];
return YES;
}
and in ViewController.m:
- (IBAction)listenButton:(UIButton *)sender
{
_rdio = [AppDelegate rdioInstance];
[self.rdio preparePlayerWithDelegate:nil];
[self.rdio.player playSource:#"p12691138"];
}
Feeling silly that I didn't get that at first! Leaving it up here in case it helps anybody.
Related
How to call native iOS viewController' code when in RN?
Like use RN to push to a native iOS viewController and then let the native code do the job.
You need to use Export Method .
AppDelegate.h
#import <UIKit/UIKit.h>
#import "RCTBridgeModule.h"
#interface AppDelegate : UIResponder <UIApplicationDelegate,RCTBridgeModule>
#property (nonatomic, strong) UIWindow *window;
#end
AppDelegate.m
#implementation AppDelegate
RCT_EXPORT_MODULE()
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//NO Change Here
}
RCT_EXPORT_METHOD(pushVC:(NSString *)vcName){
Class ctrlClass = NSClassFromString(vcName);
UIViewController *newVc = [[ctrlClass alloc] initWithNibName: vcName bundle: nil];
[[UIApplication sharedApplication].delegate.window.rootViewController presentViewController:newVc animated:YES completion:nil];
}
You can call above response in javascript like this:
import { NativeModules } from 'react-native'
NativeModules.AppDelegate.pushVC('viewControllerNameHere')
But I highly recommend to make with external file to bridge like documentation explain here:
https://facebook.github.io/react-native/docs/native-modules-ios
Ive been hitting the wall for two days on this hard (but simple for you) problem.
The problem is as follows:
I am posting a notification in the appdelegate
I am attempting to receive that notification in a viewcontroller but I cannot receive it.
Here is the code for this.
In the appdelegate.h
#import <UIKit/UIKit.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) NSString * someString;
#end
In the appdelegate.m
#import "AppDelegate.h"
#import "SomeContextExample.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.someString = #"Hello!";
NSDictionary * userInfo = #{SomeContextExampleRef : self.someString};
[[NSNotificationCenter defaultCenter] postNotificationName:#"SomeContextExample"
object:nil
userInfo:userInfo];
return YES;
}
The "SomeContextExampleRef" is coming from a .h file as follows:
#ifndef SampleNotWorking_SomeContextExample_h
#define SampleNotWorking_SomeContextExample_h
#define SomeContextExampleRef #"SomeContextExampleRef"
#endif
Finally, in the viewController.m:
#import "ViewController.h"
#import "SomeContextExample.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
[[NSNotificationCenter defaultCenter] addObserverForName:#"SomeContextExample"
object:nil
queue:mainQueue
usingBlock:^(NSNotification *note)
{
NSLog(#"got the notification!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! %#", note.userInfo);
}];
}
My full code is attached here:
https://github.com/moomoo23/SampleNotWorking
Thank you for helping a beginner!
Try posting your notification when you are confident your "ViewController" object has instantiated and/or come into view. E.G. why not try it out by putting it into an "IBAction" method fired by some UIButton?
The observing view controller may or may not (more likely not in your case) be existing at the end of "application:didFinishLaunchingWithOptions:" in your app delegate.
Another alternative is to post the notification after a delay using the scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: method.
Now, conceptually, why would you post a notification when the appFinsihedLaunching?.... just curious.... e
I have been creating a simple example app to demonstrate playing sound files in IOS.
For this I have created a very simple XCode project with one view controller. However, although my AppDelegate.h and .m files have remained unedited I am getting strange parse issues in the AppDelegate.m.
On the line #Implimentation the compiler tells me its missing '#end'.
On the line -(BOOL) application: (UIApplication ) application didFinishLaunchingWithOptions: (NSDictionary) launch options it tells me Expected ';' after method prototype.
The issues seem to stem from the #import "ViewController.h" reference in the AppDelegate.m file. As when I remove this these two errors go away, and get replaced with Receiver 'ViewController' for class message is a forward declaration, which is what I would expect with a missing import.
This is an odd problem. I've built several IOS apps before but never encountered this issue. For background info the project was created as a Single View App in XCode 4. I have properly lined the IBOutlets and Properties of the ViewController.h to the XIB in interface builder. I have also added in the AudioToolbox framework in via the build phases > Link Library with Libraries feature.
Here is the delegete and view controller files files
AppDelegate.m
#import "AppDelegate.h"
#import "ViewController.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
#end
AppDelegate.h
#import <UIKit/UIKit.h>
#class ViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) ViewController *viewController;
#end
ViewContoller.m
#import "ViewController.h"
#import <AudioToolbox/AudioToolbox.h>
#interface ViewController ()
SystemSoundID pig;
SystemSoundID cow;
SystemSoundID sheep;
SystemSoundID chicken;
#end
#implementation ViewController
#Synthesize but_cow, but_pig, but_sheep, but_chicken;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString * cowSoundURL= [[NSBundle mainBundle] pathForResource:#"cow" ofType: #"mp3"];
NSString * pigSoundURL= [[NSBundle mainBundle] pathForResource:#"pig" ofType: #"mp3"];
NSString * sheepSoundURL= [[NSBundle mainBundle] pathForResource:#"sheep" ofType: #"mp3"];
NSString * chiickenSoundURL= [[NSBundle mainBundle] pathForResource:#"chicken" ofType: #"mp3"];
AudioServicesCreateSystemSoundID(cowSoundURL, &cow);
AudioServicesCreateSystemSoundID(pigSoundURL, &pig);
AudioServicesCreateSystemSoundID( sheepSoundURL, &sheep);
AudioServicesCreateSystemSoundID(chickenSoundURL, &chicken);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//====================================================
/**
Called when a button is pressed
**/
//====================================================
-(IBAction)buttonPressed:(id)sender
{
if (sender == but_cow)
{
AudioServicesPlaySystem(cow);
}
else if (sender == but_sheep)
{
AudioServicesPlaySystem(sheep);
}
else if (sender == but_pig)
{
AudioServicesPlaySystem(pig);
}
else if (sender == but_chicken)
{
AudioServicesPlaySystem(chicken);
}
}//===================================================
#end
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (nonatomic, retain) IBOutlet UIButton * but_cow;
#property (nonatomic, retain) IBOutlet UIButton * but_pig;
#property (nonatomic, retain) IBOutlet UIButton * but_sheep;
#property (nonatomic, retain) IBOutlet UIButton * but_chicken;
-(IBAction)buttonPressed:(id)sender;
Thanks very much for taking the time to read this.
ViewController.h seems to be missing an #end
The line:
#import "ViewController.h"
will basically copy in the entire file, so if there is an error in ViewController.h, it will show up everywhere that file is imported as well.
You are not adding #end in viewcontroller.h
I'm using Safari to browse a webpage. After I click a button on this page, my Ipad will launch my app. So I implement the method - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url in the AppDelegate.m.
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
if (!url) { return NO; }
NSString *URLString = [url absoluteString];
self.paramArray = [URLString componentsSeparatedByString:#"#"];
NSLog(#"%d",[self.paramArray count]);
for (int i = 1; i < [self.paramArray count]; i++) {
NSLog([self.paramArray objectAtIndex:i]);
}
return YES;
}
The url I used on the webpage was some thing like myapp://#first_part#second_part#third_part. self.paramArray stores the substrings of url (myapp:// first_part second_part third_part).
Now I want to show these strings in the textfields in my ViewController. How can I pass this NSArray to the ViewController?
This is just a few line of code, required to accomplish it.
Put this line in appDelegate.h file
First of all you need to conforms to a protocol as follow
#interface AppDelegate : UIResponder <UIApplicationDelegate>
Now need to declare one property for it to use as follow
#property (strong, nonatomic) id<UIApplicationDelegate>delagete;
Now the last and final stage to use the property in view controller is as follow
In .h file of viewcontroller
First put reference to appdelegate like this #import "AppDelegate.h"
Then one iVar as AppDelegate *appDel; in #interface
Now in .m file
put appDel = [[UIApplication sharedApplication]delegate]; in view did load method and access the appdelegate's all property there like appDel.paramArray.
Happy Coding :)
I am trying to make a tab bar application, first i followed This Facebook grap api tutorial and my project was working fine like in picture when I touch to login, display popups
after that I have added only a tab bar and I am lost, No errors but program does not launch facebook login display. I have used breakpoints to understand why program doesnt launch facebook login display but couldnt understand because it just stuck no errors. it has to be something with tab bar.
Now it programs stucks at popin up facebook login display
my app delegate.h
#import <UIKit/UIKit.h>
#class FBFunMe;
#interface FBFunAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UITabBarController *rootController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UITabBarController *rootController;
#end
app delegate.m
#import "FBFunAppDelegate.h"
#import "FBFunMe.h"
#import "FBFunLoginDialog.h"
#implementation FBFunAppDelegate
#synthesize window = _window;
#synthesize rootController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window addSubview:rootController.view];
[self.window makeKeyAndVisible];
return YES;
}
I know rest of the code is working because i have an identical project without tab bar that works fine.
Any suggestion or example code to make it work?
_____-----------EDIT------------________
In app delegate when i try this code it display FBFunLoginDialog which what i need but i still need to this in my login button not in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
because i call some variables and appID and staff in order to login to the Facebook
FBFunLoginDialog *loginController=[[FBFunLoginDialog alloc] init];
[self.window addSubview:rootController.view];
[self.rootController presentModalViewController:loginController animated:YES];
[window makeKeyAndVisible];
return YES;
in FBFunMe.h
#interface FBFunMe :UIViewController <FBFunLoginDialogDelegate,UITextFieldDelegate> {
FBFunLoginDialog *_loginDialog;
UIView *_loginDialogView;
}
in FBFunMe.M
- (IBAction)loginButtonTapped:(id)sender {
NSString *appId = #"3888888883";
NSString *permissions = #"publish_stream";
if (_loginDialog == nil) {
self.loginDialog = [[[FBFunLoginDialog alloc] initWithAppId:appId
requestedPermissions:permissions delegate:self] autorelease];
self.loginDialogView = _loginDialog.view;
}
if (_loginState == LoginStateStartup || _loginState == LoginStateLoggedOut) {
_loginState = LoginStateLoggingIn;
[_loginDialog login];
} else if (_loginState == LoginStateLoggedIn) {
_loginState = LoginStateLoggedOut;
[_loginDialog logout];
}
[self refresh];
}