In my iOS newsstand app i need to access the default created viewContoller object in my appDelegate to start the background download when a notification arrives.
The problem is the viewController i want to access is not the root viewcontroller, if thats the case i can access it as follows,
MyViewController* mainController = (MyViewController*) self.window.rootViewController;
It would be great if anyone could guide me on this.
thanks.
have you tried as following methods,
In your AppDelegate.h.
#property (nonatomic, retain) HAViewController * haViewController;
In your AppDelegate.m
#synthesize haViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.haViewController = [[HAViewController alloc] init];
return YES;
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[self.haViewController startupdate];
}
Thanks!
Related
Is there a way i can execute the
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
method while the app is running from a different ViewController?
Maintain a separate method in your app delegate for setting nav bar appearance.
In your AppDelegate.h file, declare the same method.
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
-(void)setNavBarAppearance;
#end
In the appDelegate.m file, write the functionality for that method
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[self setNavBarAppearance];
}
-(void)setNavBarAppearance {
//Do what is required here.
}
#end
Then, wherever you need to call the same method:
#import "AppDelegate.h"
AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
[appDelegate setNavBarAppearance];
You should not call the delegate methods by your own, You can use NSNotificationCenter
Write the code you want to execute in a different method (someThingInterestingHappened) in our case.
Register the class to notification by calling addObserver on defaultNotificationCenter , i.e. [[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(someThingInterestingHappened:) name:#"desiredEventHappend" object:nil];
Post the notification from any class [[NSNotificationCenter defaultCenter] postNotificationName:#"desiredEventHappend" object:nil];
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.
Hi all I'm new in creating app for iOS , so sorry if the question stupid a little .
I'm trying to build app where log in to Facebook and getting friend list is only a part, so I want to use the example providing from Facebook to developers , but it have appDelegate file with some methods like this:
#import "FPAppDelegate.h"
#import "FPViewController.h"
#implementation FPAppDelegate
#synthesize window = _window;
#synthesize rootViewController = _rootViewController;
- (BOOL)application:(UIApplication *)application
.......
return [FBSession.activeSession handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[FBFriendPickerViewController class];
........
return YES;
}
- (void)applicationWillTerminate:(UIApplication *)application {
[FBSession.activeSession close];
}
And it have xib file for FPViewController with h and m files, so what the better way to use this example in my app, I understand that I can't use two appDelegate files, and I trying to change FPAppDelegate that is UIResponder to UIViewController class to push it from some place in my app like this:
- (IBAction)loginFacebook:(id)sender
{
NSLog(#"Facebook");
delegateViewController *appDelegate = [[delegateViewController alloc] initWithNibName:nil bundle:NULL];
[self.navigationController pushViewController: appDelegate animated:YES];
}
where delegateViewController is FPAppDelegate of example I changing to:
#import "delegateViewController.h"
#import "AppDelegate.h"
#import "FPViewController.h"
#interface delegateViewController ()
#end
#implementation delegateViewController
#synthesize window2=_window2;
#synthesize rootViewController2=_rootViewController2;
- (BOOL)application:(UIApplication *)application
......
return [FBSession.activeSession handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[FBFriendPickerViewController class];
......
self.window2 = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window2.rootViewController = navigationController;
[self.window2 makeKeyAndVisible];
return YES;
}
- (void)applicationWillTerminate:(UIApplication *)application {
........
[FBSession.activeSession close];
}
but it's not working, so, if I need to change also xib file? Or to change appDelegate file of my project? Or existing another way to use this example in my app? I would like you to explain this to me.
You should start by working through the Apple tutorials so you can understand the UIKit framework to start developing an iOS app.
http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/chapters/Introduction.html
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];
}