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
Related
I want to capture the iOS native errors to Sentry and also capture some custom messages.
I'm using the sentry-expo library but this only captures javascript errors even with the parameter:
deactivateStacktraceMerging: false
I'v been following the official installation guide https://docs.sentry.io/clients/react-native/ but I'm stuck when trying to configure the AppDelegate.m file
#import "AppDelegate.h"
#import "ExpoKit.h"
#import "EXViewController.h"
#import <Fabric/Fabric.h>
#import <Crashlytics/Crashlytics.h>
#if __has_include(<React/RNSentry.h>)
#import <React/RNSentry.h> // This is used for versions of react >= 0.40
#else
#import "RNSentry.h" // This is used for versions of react < 0.40
#endif
#interface AppDelegate ()
#property (nonatomic, strong) EXViewController *rootViewController;
#end
#implementation AppDelegate
-(EventsObserver*)getEventsObserver
{
return EventsObserver.shared;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Fabric with:#[[Crashlytics class]]];
[application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
_window.backgroundColor = [UIColor whiteColor];
[[ExpoKit sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
_rootViewController = [ExpoKit sharedInstance].rootViewController;
_window.rootViewController = _rootViewController;
[_window makeKeyAndVisible];
[self getEventsObserver];
[RNSentry installWithRootView:rootView];
return YES;
}
At this point I don't have the rootView object of type RCTRootView. I'm using a EXViewController and the library does not support that type of object to invoke the function installWithRootView. Am I following a wrong path?
I am using Xcode 8 and objective-c. I followed the Facebook guidelines and yet my login button does not switch to a log out button after logging in with my app's Admin user. I'm a bit new to app development so I'm not sure where to look in the Facebook SDK. I read some posts online and they seemed to point to the guidelines (i.e., the issues were solved by following the guidelines closely). I should mention that after logging in again, I get a "you have already authorized {{app}}" message from Facebook with a Cancel and OK button.
Here's the view controller's implementation file:
#import "LoginViewController.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#interface LoginViewController ()
#property (weak, nonatomic) IBOutlet FBSDKLoginButton *loginButton;
#end
#implementation LoginViewController
-(void)loginButtonDidLogOut:(FBSDKLoginButton *)loginButton {
}
- (void)loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result error:(NSError *)error
{
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.loginButton.readPermissions = #[#"public_profile", #"email", #"user_friends"];
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.center = self.view.center;
[self.view addSubview:loginButton];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
And the header for the controller view:
#import <UIKit/UIKit.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#interface LoginViewController : UIViewController <FBSDKLoginButtonDelegate>
And the AppDelegate's implementation parts that Facebook indicated to change / add:
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
return YES;
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
I basically copied / pasted from Facebook's steps so I'm at a loss as to what to do next. Thanks for any help
Did some more digging and found this solution, which worked for me:
FBSDK Login Error Code: 308 in Objective-C
Note the solution I used is not the highest voted answer in that link. Here are the details for convenience:
Enable keychain sharing in the project (in project-level settings)
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.
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!