facebook login currentAccessToken return null - facebook-access-token

There is a problem with use Facebook SDK login.
The code is there.in AppDeledate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
BOOL flag = [[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
…………
return flag
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation{
BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation
];
return handled;
}
And in the costomer VC
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
// Do any additional setup after loading the view.
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.delegate = self;
loginButton.readPermissions = #[#"public_profile", #"email"];
loginButton.center = self.view.center;
[self.view addSubview:loginButton];
}
when I called [FBSDKAccessToken currentAccessToken] after loginbutton click and login success(In my facebook setting applications i found the app exist), the Token always null

Related

push token's delegte method not invoke in Specifically in iPhone 5s with ios 12.4.5

I had integrated VoIP and remote notification in my app, but Specifically, in iPhone 5s with ios 12.4.5. I did get a VoIP token or remote token. UIApplicationDelegate's toke method and PKPushRegistryDelegate's token method not invoke. what's wrong here I already tried with a strong network of cellular instead of connecting with wifi. and other variants of the iPhone like iPhone 6 and iPhone XR working fine. Please help me with this issue.
I had used a push notification certificate with mention below for both remote and VoIP push.
here is my code
#interface AppDelegate : UIResponder <UIApplicationDelegate,PKPushRegistryDelegate,UNUserNotificationCenterDelegate>
{
PKPushRegistry *voipRegistry;
}
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self pushNotificationRegister];
return true;
}
-(void)pushNotificationRegister
{
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
UNAuthorizationOptions options = UNAuthorizationOptionAlert + UNAuthorizationOptionSound + UNAuthorizationOptionBadge;
center.delegate = self;
[center requestAuthorizationWithOptions:options completionHandler:^(BOOL granted, NSError * _Nullable error){
if( !error ){
dispatch_async(dispatch_get_main_queue(), ^{
[self voipRegistration];
[UIApplication.sharedApplication registerForRemoteNotifications];
});
}
}];
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
if (settings.authorizationStatus != UNAuthorizationStatusAuthorized) {
}
}];
}
- (void) voipRegistration
{
voipRegistry = [[PKPushRegistry alloc] initWithQueue: dispatch_get_main_queue()];
voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
voipRegistry.delegate = self;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
// Not invoke
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
// Not invoke
}
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)pushCredentials forType:(PKPushType)type
{
// Not invoke
}
- (void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(PKPushType)type
{
// Not invoke
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound);
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler
{
completionHandler();
}
#end

UICollectionView in UINavgationController

I want to do a simple example.
I have a rootViewController that is a UINavgationController, and there is a UIViewController in that UINavgationController. Now I want to create UICollectionView in the UIViewController, but I am getting an error.
here is the code:
#import "AppDelegate.h"
#import "XJViewController.h"
#interface AppDelegate ()
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
XJViewController *xjv = [[XJViewController alloc]init];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:xjv];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
#import <UIKit/UIKit.h>
#interface XJViewController : UIViewController<UICollectionViewDelegate,UICollectionViewDataSource>
#end
#import "XJViewController.h"
#interface XJViewController ()
#end
#implementation XJViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
self.title = #"XJ";
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
NSDictionary *dicColor = #{NSForegroundColorAttributeName : [UIColor whiteColor]};
self.navigationController.navigationBar.titleTextAttributes = dicColor;
UICollectionViewFlowLayout *fLayout = [[UICollectionViewFlowLayout alloc]init];
UICollectionView *cv = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:fLayout];
[cv registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:#"myeCell"];
cv.dataSource = self;
cv.delegate = self;
[self.view addSubview:cv];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 4;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"myCell" forIndexPath:indexPath];
cell.backgroundColor = [UIColor redColor];
return cell;
}
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view
of kind: UICollectionElementKindCell with identifier myCell - must
register a nib or a class for the identifier or connect a prototype
cell in a storyboard'
Please help me figure out what the problem is.
[cv registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:#"myeCell"];
The identifier here is different from the one you are using in -cellForItemAtIndexPath

Warning: Attempt to present UINavigationController on SampleViewController: whose view is not in the window hierarchy

i have try all the solution in this forum but still cannot solve. Can anybody help me out with these problem? i want the app to open the inboxData class that contain a tableView when the NSUserDefault read the key #"url" from Urban Airship..
this is from SampleViewController class;
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *action_9 = [defaults objectForKey:#"url"];
if ([[[NSUserDefaults standardUserDefaults]objectForKey:#"url"] isEqualToString:#"aa9"])
{
inboxData *screen=[[inboxData alloc]initWithNibName:#"inboxData" bundle:nil];
screen.strGetTableSelect=#"1";
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:screen];
[self presentModalViewController:navigationController animated:YES];
}
}
it return with these error..
Warning: Attempt to present UINavigationController on SampleViewController whose view is not in the window hierarchy
Your SampleViewController not in the Window hierarchy, You need to set in window.
In your appDelegate, do like this,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[SampleViewController alloc] initWithNibName:#"SampleViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
If you are using storyboad, Use like this in didFinishLaunchingWithOptions method,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone"
                                                             bundle: nil];
 
    SampleViewController *mainViewController = (SampleViewController*)[mainStoryboard
                                                       instantiateViewControllerWithIdentifier: #"SampleViewController"];
 
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window setRootViewController:navigationController];
    [self.window setBackgroundColor:[UIColor whiteColor]];
    [self.window makeKeyAndVisible];
 
    return YES;
}
In your view controller,
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *action_9 = [defaults objectForKey:#"url"];
if ([[[NSUserDefaults standardUserDefaults]objectForKey:#"url"] isEqualToString:#"aa9"])
{
inboxData *screen=[[inboxData alloc]initWithNibName:#"inboxData" bundle:nil];
screen.strGetTableSelect=#"1";
[self presentModalViewController:screen animated:YES];
}
}

Audio playing not working when ios device is locked

I am doing the following things to make audio play when an iOS device is locked, but it doesn't work.
UIBackgroundModes key (with the value audio) in Info.plist file.
set up audio session
code:
- (void)viewDidLoad
{
[super viewDidLoad];
[self createAudioSession];
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:#"jgj" ofType:#"mp3"];
NSURL *url = [NSURL fileURLWithPath:soundFilePath];
NSLog(#"%#",[url path]);
NSError* error;
self.audioPlayer=[[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
if (self.audioPlayer == nil)
NSLog(#"%#",[error description]);
else
{
self.audioPlayer.numberOfLoops=-1;
[self.audioPlayer play];
}
}
-(void)createAudioSession
{
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
// Use this code to allow the app sound to continue to play when the screen is locked.
NSError* error=nil;
BOOL ok=[audioSession setCategory: AVAudioSessionCategoryPlayback error: &error];
if(!ok)
NSLog(#"%#",[error description]);
else
NSLog(#"hello");
ok=[audioSession setActive:YES error:&error];
if(!ok)
NSLog(#"%#",[error description]);
else
NSLog(#"world");
}

ZUUIRevealController - Memory allocations keeps on increasing & slow UIAlertView & UIActionsheet

I am starting with new iOS app in which I have to use Reveal control. So I planned to use great ZUUIRevealController library. I just created UI for 2 - 3 screens . In one of those screen I have to shown UIAlertView & UIActionsheet. But I realised that UIAlertView & UIActionsheet shows very slowly (it adds black overlay first & then shows UIAlertView/UIActionsheet, kind of alert view hangs while showing. Animation is not smooth). I didn't added any logic for coding just created the UI. I didn't use any background thread / dispatch_asyn(). So there is no issue of updating UI from background thread. So I checked the memory leaks & allocations. I didn't see any memory leaks , but memory allocations keeps on increasing while I reveal the menu & push new view controller. It doesn't decrese when I pop the view controller. Here are the screenshots :
1) When app launches
2) After some time , when I push new view controller, pop view controller
I know ZUUIRevealController library creates new instance of view controller every time I select a row from Menu. So I crated the instance variables of view controllers in .h file , but still I have same problem.
Here is my code
// AppDelegate.m
// On SplashViewController , I decide whether to show menu or Login screen
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.splashViewController = [[SplashViewController alloc]initWithNibName:#"SplashViewController" bundle:nil];
self.window.rootViewController = self.splashViewController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[self customizeUIControlsAppearance];
return YES;
}
// SplashViewController.m
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
BOOL isLoggedIn = YES;
if(isLoggedIn){
[self showMenuViewController];
}
else{
[self showStartUpViewController];
}
}
-(void)showStartUpViewController
{
StartUpViewController *startUpViewController = [[StartUpViewController alloc]initWithNibName:#"StartUpViewController" bundle:nil];
UINavigationController *navController=[[UINavigationController alloc] initWithRootViewController:startUpViewController];
[self presentViewController:navController animated:NO completion:^{
}];
}
-(void)showMenuViewController
{
MenuViewController *menuViewController=[[MenuViewController alloc] init];
CategoryViewController *categoryViewController=[[CategoryViewController alloc]initWithNibName:#"CategoryViewController" bundle:nil];
categoryViewController.isViewControllerShownFromMenu = YES;
UINavigationController *navController=[[UINavigationController alloc] initWithRootViewController:categoryViewController];
RevealController *revealController=[[RevealController alloc] initWithFrontViewController:navController rearViewController:menuViewController];
[self presentViewController:revealController animated:NO completion:^{
}];
}
// MenuViewController.m
// SettingsViewController & NewsViewController are decalred in .h file with property & syntheszie
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
RevealController *revealController = [self.parentViewController isKindOfClass:[RevealController class]] ? (RevealController *)self.parentViewController : nil;
// Switch using Section Number
switch (indexPath.section) {
case OTHER_SECTION:
switch (indexPath.row) {
case NEWS:
[self showNewsViewControllerUsingRevealController:revealController];
break;
case SETTINGS:
[self showSettingsViewControllerUsingRevealController:revealController];
break;
default:
break;
}
break;
default:
break;
}
}
#pragma mark - Show News & Settings View Controllers
-(void)showNewsViewControllerUsingRevealController:(RevealController*)revealController
{
if ([revealController.frontViewController isKindOfClass:[UINavigationController class]] && ![((UINavigationController *)revealController.frontViewController).topViewController isKindOfClass:[NewsViewController class]])
{
if(!self.newsViewController)
self.newsViewController = [[NewsViewController alloc] initWithNibName:#"NewsViewController" bundle:nil];
self.newsViewController.isViewControllerShownFromMenu = YES;
UINavigationController *navigationController= [[UINavigationController alloc] initWithRootViewController:self.newsViewController];
[revealController setFrontViewController:navigationController animated:NO];
}
else
{
[revealController revealToggle:self];
}
}
-(void)showSettingsViewControllerUsingRevealController:(RevealController*)revealController
{
if ([revealController.frontViewController isKindOfClass:[UINavigationController class]] && ![((UINavigationController *)revealController.frontViewController).topViewController isKindOfClass:[SettingsViewController class]])
{
if(!self.settingsViewController)
self.settingsViewController= [[SettingsViewController alloc] initWithNibName:#"SettingsViewController" bundle:nil];
self.settingsViewController.isViewControllerShownFromMenu = YES;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.settingsViewController];
[revealController setFrontViewController:navigationController animated:NO];
}
else
{
[revealController revealToggle:self];
}
}
// Code for shwoing UIAlertView & UIActionsheet
-(void)showAlertWithTitle:(NSString*)title andMessage:(NSString*)message
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:title message:message delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
}
-(void)btnInviteTapped:(id)sender event:(UIEvent*)event
{
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:NSLocalizedString(#"FRIENDS_VC:INVIT_ACTIONSHEET_TITLE", nil) delegate:self cancelButtonTitle:NSLocalizedString(#"FRIENDS_VC:ACTIONSHEET_CANCEL_BUTTON",nil) destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(#"FRIENDS_VC:ACTIONSHEET_SMS_BUTTON",nil),NSLocalizedString(#"FRIENDS_VC:ACTIONSHEET_EMAIL_BUTTON",nil), nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[actionSheet showInView:self.view];
}
By the way I have 11 menu items.
My Login & Regsiter flow is not embedded in MenuViewController. On Login & REgsiter , UIAlertView & UIActionSheet shows smoothly.
Any idea whats going wrong here ? Did I make some mistake in coding ?
Why my UIAlertView & UIActionsheet are not showing smoothly ?
Any kind of help is appreciated. Thanks.

Resources