Segue after openURL in AppDelegate - ios

I have a button with a action (toggleApplication) that opens another application. When I return to my application from the one that was opened I want to segue to another view. But I get the following error from my code:
Receiver (RootViewController: 0x1f192450) has no segue with identifier 'showReceipt'
AppDelegate.m
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
RootViewController *controller = [RootViewController alloc];
return [controller handleURL:url];
}
RootViewController.m
- (IBAction)toggleApplication:(id)sender{
// Open application
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:theUrlString]];
}
- (BOOL)handleURL:(NSURL *)url{
[self performSegueWithIdentifier:#"showReceipt" sender:self];
return YES;
}

Figured it out by using NSNotificationCenter.
AppDelegate.m
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
[[NSNotificationCenter defaultCenter] postNotificationName:#"segueListener" object:nil];
return YES;
}
RootViewController.m
- (void)viewDidLoad{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(receiptSegue) name:#"segueListener" object:nil];
}
- (IBAction)toggleApplication:(id)sender{
// Open application
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:theUrlString]];
}
- (void)receiptSegue{
[self performSegueWithIdentifier:#"showReceipt" sender:self];
}
Does exactly what I want. Don't know if it's the right approach though.

Related

Why its not showing anything when i open the app with url?

I have following setup, when i open my app (app number 2 open by app number 1 using url) using url in iPhone 7, then i am not getting any url inputs.
its not showing any alert box at all.
How do i check if i am receiving the url input in my app at all or not?
AppDelegate.m:
#import "AppDelegate.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
ViewController.m:
-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
//if (url != nil && [url isFileURL]) {
//[self.ViewController handleOpenURL:url];
//}
id test = (NSURL *) url;
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:#"My Title"
message:test
preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alert animated:YES completion:nil];
//NSLog(#">>> got <<< >>> <<< !!!! >>>> : %#", url);
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
}
The problem is that
-(BOOL) application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
... is a UIApplicationDelegate method. So it can't be located in ViewController.m. It needs to be in AppDelegate.m.

iOS Facebook SDK 4 FBSDKShareDialog

I have some trouble when I try to implement FBSDKShareDialog to perform facebook sharing via my app. If official fb app is installed it shows blank dialog (where user allows to type some text etc). If user doesn't have fb app it shows correct info but FBSDKSharingDelegate methods doesn't work. (It doesn't work even when user has fb application)
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NSLog(#"complete");
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer
{
NSLog(#"did cancel");
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
NSLog(#"%#", error);
}
It's never called even when I cancel or share via FB application.
My code is:
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentTitle = _place.title;
content.imageURL = [NSURL URLWithString:_place.logoUrl];
content.contentDescription = _place.info;
[FBSDKShareDialog showFromViewController:_viewController withContent:content delegate:self];
I have a delegate inside #interface declaration.
#interface FacebookHandler () < FBSDKSharingDelegate >
#end
My app delegate has
#import <FBSDKCoreKit/FBSDKCoreKit.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return [[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
Where I was wrong? And is it good idea to post some image and title via FBSDKShareLinkContent. Thanks in advance.
Are you calling [FBSDKShareAPI shareWithContent:content delegate:self] from the main thread?
I've already fixed this issue. The problem was that I've delegate to file inherited from NSObject, which can't be a delegate

Facebook SDK share always returns sharerDidCancel [duplicate]

This question already has answers here:
FBSDKShareDialog cancels when it should post
(4 answers)
Closed 7 years ago.
I'm trying to share a post with the Facebook SDK, but sharerDidCancel is always called, either if I share or cancel the post.
Here is my code
- (void)shareFacebook {
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"http://www.google.com"];
[FBSDKShareDialog showFromViewController:view
withContent:content
delegate:self];
}
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults :(NSDictionary*)results {
NSLog(#"FB: SHARE RESULTS=%#\n",[results debugDescription]);
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error {
NSLog(#"FB: ERROR=%#\n",[error debugDescription]);
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer {
NSLog(#"FB: CANCELED SHARER=%#\n",[sharer debugDescription]);
}
This class implements the FBSDKSharingDelegate, in my Info.plist I already entered the FacebookAppID and FacebookDisplayName.
In my AppDelegate I have this method:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
}
What I'm doing wrong? I exactly followed the Facebook SDK guide.
Thanks
Solved, my error was in the AppDelegate method:
here is a link with the solution http://jitu1990.blogspot.it/2015/05/share-with-facebook-from-ios-app.html
And here is the code
- (BOOL)application:(UIApplication *)application openURL:(NSURL* )url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url sourceApplication:sourceApplication annotation:annotation];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return [ [FBSDKApplicationDelegate sharedInstance] application :application
didFinishLaunchingWithOptions:launchOptions]
}

how to call viewWillAppear after redirecting from safari to view controller in IOS

I am using Flickr in my app. When I click on Flickr button it is redirecting to safari to login with Flickr and Authorization.
Then after successful authorization it is redirecting to my app. But after redirecting I want to call ViewWillAppear. I also set <UIApplicationDelegate> at my view. But it is not calling any of the below methods.
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
NSLog(#"#####################Flickr Authorized is completed");
}
- (void)UIApplicationWillEnterForeground:(UIApplication *)application
{
NSLog(#"#####################Flickr Authorized is completed at foreground");
}
- (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.
*/
NSLog(#"#####################Flickr Authorized is completed at become active");
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
NSLog(#"######################Flickr Authorized is completed at openURL");
}
-(void)viewWillAppear:(BOOL)animated
{
NSLog(#"#####################Flickr Authorized is completed at viewWillAppear");
[super viewWillAppear:YES];
}
But Below method is calling after redirecting from safari at AppDelegate. I have used Code from SnapAndRun flickr sample.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
NSLog(#"######################Call Back Here###########");
if ([self flickrRequest].sessionInfo)
{
// already running some other request
NSLog(#"Already running some other request");
}
else {
NSString *token = nil;
NSString *verifier = nil;
BOOL result = OFExtractOAuthCallback(url, [NSURL URLWithString:SRCallbackURLBaseString], &token, &verifier);
if (!result) {
NSLog(#"Cannot obtain token/secret from URL: %#", [url absoluteString]);
return NO;
}
[self flickrRequest].sessionInfo = kGetAccessTokenStep;
[flickrRequest fetchOAuthAccessTokenWithRequestToken:token verifier:verifier];
[activityIndicator startAnimating];
//[viewController.view addSubview:progressView];
}
return YES;
}
I know that we can call my view controllers method here. But Is there any alternative for default delegate method to be called after redirecting at my view itself.
Any Suggestions will be appreciated.
Thanks in Advance.
You can use notificationCenter.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(someMethod:) name:#"UIApplicationDidBecomeActiveNotification" object:nil];

How to use UIApplication handleOpenURL Notifications

I am trying to handle UIApplication Notifications to get URL Schemes in current open view. I have tried several notifications but i don't know which object contains the URL Schemes.
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
//[nc addObserver:self selector:#selector(DocumentToDropboxDelegate) name:UIApplicationWillResignActiveNotification object:nil];
[nc addObserver:self selector:#selector(DocumentToDropboxDelegate) name:UIApplicationDidFinishLaunchingNotification object:nil];
Can someone pelase help me with this issue.
As #Mike K mentioned you'll have to implement one (or both) of the following methods:
- application:handleOpenURL:
- application:openURL:sourceApplication:annotation:
on your UIApplicationDelegate. There is no matching notification for them.
Example below:
-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
if (url != nil && [url isFileURL]) {
[self.viewController handleOpenURL:url];
}
return YES;
}
//Deprecated
-(BOOL) application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if (url != nil && [url isFileURL]) {
[self.viewController handleOpenURL:url];
}
return YES;
}
application:handleOpenURL: is called on your application delegate - not via a NSNotification. the preferred delegate method to implement is: application:openURL:sourceApplication:annotation:.
more info can be found here:
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:handleOpenURL:

Resources