I'm using the application:openURL:sourceApplication:annotation: to open a file with an extension .ftl. This is declared in my app's info property list.
The .ftl file is attached to an email, and when touched calls an ALREADY LAUNCHED app. The code works fine in IOS 4, but in IOS 6 the above app delegate method isn't called.
The code is in my app delegate is simply:
-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
NSLog(#"method is called");
if (url != nil && [url isFileURL]) {
[self performSelector:#selector(splashFade) withObject:nil];
NSLog(#"inside if statement called");
//Calls singleton to delete existing data, parse and ingest supplied new file data into Coredata:
[[ContentController sharedInstance] deleteSectorList:(NSURL *)url];
}
return YES;
}
Does anyone have any idea why this method is no longer called?
Thanks.
You have to tell the phone that your app accepts certain files. You do this by going to the info.pList and there you add a flag.
Follow this link which will cover this subject. https://developer.apple.com/library/ios/#documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/RegisteringtheFileTypesYourAppSupports.html%23//apple_ref/doc/uid/TP40010411-SW1
Related
For this problem, I created a new project with a single view.
I set a url scheme and added a label in the view.
And code is here.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
ViewController *vc = (ViewController *)self.window.rootViewController;
vc.textLabel.text = [NSString stringWithFormat:#"%#\n%#",vc.textLabel.text,url.absoluteString];
return YES;
}
It works fine.
But if I add some time-consuming operations at app initialize,
like this.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[NSThread sleepForTimeInterval:1];
return YES;
}
Then I found this problem through those steps:
use safari to start the app through input the url scheme
wait it jumps to the app, and press the home button immediately
tap the app icon to continue
get two lines of url on the label
UIApplication calls application:openUrl: multiple times.
I tried using this delegate, same problem.
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
You can press the home button and tap the app icon multiple times, than openUrl will be called multiple times, it depends on cost of time-consuming operations.
I tested on iOS 9.3.3 and iOS 9.3.1, got same problem.
I tried on iOS 8.1.2 and iOS 10.2 not found this problem.
Any ideas/suggestions would be highly helpful & very thankful
I am using the FBLoginView (version 3.xx) in my app to automatically create useraccounts based on their Facebook profile, but the delegate callbacks of FBLoginViewDelegate don't get called anymore.
My code is as folloows:
In the didFinishLaunchingWithOptions method of my AppDelegate I have this line:
[FBLoginView class];
I have a class called LoginHandler that conformes to the FBLoginViewDelegate protocol and which implements these methods:
- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView
- (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user
- (void)loginView:(FBLoginView *)loginView handleError:(NSError *)error
In the viewDidLoad method of my view controller I have this code:
self.fbLoginView.readPermissions = #[#"public_profile", #"email"];
self.fbLoginView.delegate = [LoginHandler sharedInstance];
I also have set up my Info.plist with:
FacebookAppID (containing <my-app-id>)
FacebookDisplayName (containing my app name=
CFBundleURLSchemes (containing fb<my-app-id>)
When I press the Facebook login button it switches over to the Facebook app, asks about the permisions (only the first time) and returns to my app. However, none of the delegate methods get called at this point. This used to work before and I did get callbacks for both loginViewShowingLoggedInUser and loginViewFetchedUserInfo, but some time ago it stopped working and I simply can't figure out what changes have broken it.
An interesting thing is that every time I start the app (before I do anything with the Facebook button) my loginViewShowingLoggedOutUser gets called. I don't know if it is related to my issue or if this is normal behaviour.
I have found the answer. I needed to override this method in my app delegate.
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
// Call FBAppCall's handleOpenURL:sourceApplication to handle Facebook app responses
BOOL wasHandled = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
// You can add your app-specific url handling code here if needed
return wasHandled;
}
I'm struggling with following problem:
I am using the Method
(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
to set a Serverstring from extern. So when i do call myapp://serverurl/url the string url is set correctly to a NSUSerDefaults Key. That works fine so far.
But when I am currently in the Settingsview of my App, where you can set this variable manually and i call the above url for example from the Mail-App, it sets the variable, but the corresponding Textfield of the View is not updated. So the old string is still written in the Textfield but in NSUSerDefaults its updated correctly.
I tried to work with the Notification Center. I bound the the following Method:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(updateServerURLTextField) name:UIApplicationWillEnterForegroundNotification object:nil];
- (void)updateServerURLTextField
{
NSLog(#"Updating Serveraddress label");
NSString* serverFullURL = [[NSUserDefaults standardUserDefaults] objectForKey:wServerFullURLKey];
self.serverURLTextField.text = serverFullUrl;
}
The Notification gets fired so does updateServerURLTextField but its not updated. I assume some race time conditions?
- (void)applicationDidBecomeActive:(UIApplication *)application
gets called after the Notification is fired. Maybe the GUI cant be updated before the App is active?
Anyone got some hints?
You can't update the UI this way. All changes to UI need to happen on the main thread. You might consider using: PerformSelectorOnMainThread:withObject:waitUntilDone:
In the documentation from facebook to integrate their sdk in iOS app, they mentioned everything in app delegate. But in my application, i've settings view which has option for "Facebook". When user clicks that then only i want to enable single sign on from my application. This can be done by creating facebook object etc in my settings view controller. But in app delegate, they are asking to ad the following code:
// Pre 4.2 support
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [facebook handleOpenURL:url];
}
// For 4.2+ support
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [facebook handleOpenURL:url];
}
And both the above methods has to be implemented in app delegate class with "facebook" as object. But I'm creating my facebook object in my settings view controller. How should I handle this situation?
Add this to your AppDelegate.m (and add it to the .h header file)
+ (AppDelegate*) sharedAppDelegate {
return (AppDelegate*) [UIApplication sharedApplication].delegate;
}
Include the header file and do this to access your facebook object from any view controller:
[[AppDelegate sharedAppDelegate] facebook]
as mentioned in the docs, I'm creating the facebook object and calling the methods in app delegate from the settings view
I'm trying to implement SSO following the Tutorial:
https://developers.facebook.com/docs/mobile/ios/build/
At the end of Step 3, I'm supposed to Test my App running it on Simulator. The Run succeeded but all I see is a Blank View (screen). I'm not sure if I need to create the view called "authorization dialog" including the FB logo, buttons, etc or if it's automatically created by code I've implemented using Facebook SDK.
Also, I'm using a storyboard and wonder if that's the problem.
I think that it's because you have once signed in and now you haven't logged out so it is already authorized and hence you cannot see anything :)
Is your initial ViewController blankView ? Because the SSO only validates/autorize the session, you need to implement the UI in your ViewController.
If you implement it in Storyboard I suggest you to do most of the code in your controller file, since I was stucked there for quite long time. But make sure to put this code in the app delegate file.
#pragma mark Facebook
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [self.facebook handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication: (NSString *)sourceApplication annotation:(id)annotation {
return [self.facebook handleOpenURL:url];
}
Also in the delegate file you should instantiate the Facebook object before you use the in the above methods.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
viewController *controller = [[viewController alloc] init];
// Initialize Facebook
facebook = [[Facebook alloc] initWithAppId:#"Your app ID in string" andDelegate:controller];
// Override point for customization after application launch.
return YES;
}