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.
Related
My app authorizes Dropbox, which has always been good. Recently, I found that I could not jump back to my app after choosing files in Dropbox to generate links.
Below is the code in my app RRDocsController:
DBChooser *chooser = [[DBChooser defaultChooser] initWithAppKey:kDropboxAppKey];
[chooser openChooserForLinkType:DBChooserLinkTypePreview fromViewController:self completion:^(NSArray *results) {
if ([results count]) {
//do somthings...
}
}];
Below is the code in my app delegate:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
if ([[[DBChooser defaultChooser]initWithAppKey:kDropboxAppKey] handleOpenURL:url]) {
return YES;
}
return NO;
}
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
if ([[[DBChooser defaultChooser] initWithAppKey:kDropboxAppKey] handleOpenURL:url]) {
return YES;
}
return NO;}
Supplement:
When from my app jump to Dropbox, after the file selection page select files, pop-up "was generating links..." box, then the pop-up box and selection page dismiss together, but it can't to jump to my app, breakpoint tracking not callback in the appdelegate handleOpenURL: method, and the console doesn't have any log.
My phone is iPhone6 with iOS 10.3
I am following all steps as per this link Click here
After doing all steps it gives me
Can anyone tell me this strange is happening ?
Answer would be appreciated.
Thanks.
Try those:
Add GIDSignIn library header properly, if in case you missing something.
Add AppDelgate.h file into your ViewController (If you not writing this code in AppDelegate.m)
Read point 4 which I copied from GitHub forum, which can be the main reason of your errors.
It looks like iOS 9 changed the constant UIApplicationLaunchOptionsSourceApplicationKey to UIApplicationOpenURLOptionsSourceApplicationKey. Dynamically support both, especially in Xcode 6.4 which doesn't recognize UIApplicationOpenURLOptionsSourceApplicationKey.
After try these all if its still not working then comment here for further help.
This is the AppDelegate.m file from which I implemented Google Signin SDK (the new one)
#define kGoogleClientID #""
#import "AppDelegate.h"
#import <GoogleSignIn/GoogleSignIn.h>
#interface AppDelegate ()<GIDSignInDelegate>
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GIDSignIn sharedInstance].clientID = kGoogleClientID;
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
}
- (void)applicationWillTerminate:(UIApplication *)application {
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
if(annotation){
NSDictionary *options = #{UIApplicationOpenURLOptionsSourceApplicationKey: sourceApplication,
UIApplicationOpenURLOptionsAnnotationKey: annotation};
return [self application:application
openURL:url
options:options];
}
}
/* Google */
- (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)user
withError:(NSError *)error {
// Perform any operations on signed in user here.
// ...
}
- (void)signIn:(GIDSignIn *)signIn
didDisconnectWithUser:(GIDGoogleUser *)user
withError:(NSError *)error {
// Perform any operations when the user disconnects from app here.
// ...
}
#end
Hope this helps you out
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
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]
}
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.