Open my app with a URL, Then Load the link - ios

I have a web browser app with a URL Identifier/Scheme "wb".
ok, when the user typing wb:// in safari, my app will open. Perfect!
but, if the user typing "wb://www.facebook.com" in safari, I want to open "facebook.com" in my app.
How do i get the link after the "wb://" ?
I'm using (This:) in my AppDelegate.m :
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
// Display text
UIAlertView *alertView;
NSString *text = [[url host] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
alertView = [[UIAlertView alloc] initWithTitle:#"Text:" message:text delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
return YES;
}
and get the link when the users types the link.
but how did I get it to my ViewController.m so i can load my webview with the text.

You could provide an implementation for application:handleOpenUrl: in your AppDelegate like:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
// Do whatever is needed with the provided url
}

Related

FBSDKSharingDelegate callback not working, even when post works fine

FBSDKSharingDelegate callback is not working. I can post to facebook fine with the ios SDK, but I'd like to detect if the post was successful and take additional action to notify the user. However, the callback is not working for me. The delegate methods are not being called and I don't know why.
Using ios8, Parse as my backend. In Parse, the user is linked to FB. I'm using the IOS simulator.
What I've tried:
I've ensured that publish permissions are granted, saved, and linked to the Parse user. I've run a check and "publish_actions" are detected OK. The posting works fine as I can see the post on the facebook account. It's just the callback that is not working. I've checked my fb setup and it looks fine. For good measure at the very bottom I've included that relevant code from my app delegate. I've blocked out confidential keys with XXXX.
Code:
1st: See if user is logged in to Parse, if not, send to sign in and link to facebook account. Once that is done, I request "publish" permissions and link that additional permission to the Parse user. I know this works b/c when I recompile, it remembers the "publish" permissions and goes right to into the post.
#interface FacebookAPIPost () <FBSDKSharingDelegate>
#end
#implementation FacebookAPIPost
-(void)shareSegmentFacebookAPI { //if statement below
//1) logged in?, if not send to sign up screen
//2) else if logged in, link account to facebook account, then send post
//3) else send to post b/c signed up and linked already.
PFUser *currentUser = [PFUser currentUser];
if(!currentUser) {
[self pushToSignIn];
} else if(![PFFacebookUtils isLinkedWithUser:currentUser]){
[self linkUserToFacebook:currentUser];
NSLog(#"user account not linked to facebook");
} else {
[self shareSegmentWithFacebookComposer];
}
}
-(void)linkUserToFacebook:currentUser{
[PFFacebookUtils linkUserInBackground:currentUser withPublishPermissions:#[#"publish_actions"] block:^(BOOL succeeded, NSError *error) {
if(error){
NSLog(#"There was an issue linking your facebook account. Please try again.");
}
else {
NSLog(#"facebook account is linked");
//Send the facebook status update
[self shareSegmentWithFacebookComposer];
}
}];
}
-(void)shareSegmentWithFacebookComposer{
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"]) {
[self publishFBPost]; //publish
} else {
NSLog(#"no publish permissions"); // no publish permissions so get them, then post
[PFFacebookUtils linkUserInBackground:[PFUser currentUser]
withPublishPermissions:#[ #"publish_actions"]
block:^(BOOL succeeded, NSError *error) {
if (succeeded) {
NSLog(#"User now has read and publish permissions!");
[self publishFBPost];
}
}];
Here is where the post gets made:
-(void) publishFBPost{
FBSDKShareLinkContent *content = [FBSDKShareLinkContent new];
content.contentURL = [NSURL URLWithString:[self.selectedSegment valueForKey:#"linkToContent"]];
content.contentTitle = [self.selectedProgram valueForKey:#"programTitle"];
content.contentDescription = [self.selectedSegment valueForKey:#"purposeSummary"];
PFFile *theImage = [self.selectedSegment valueForKey:#"segmentImage"];
NSString *urlString = theImage.url;
NSURL *url = [NSURL URLWithString:urlString];
content.imageURL = url;
FBSDKShareDialog *shareDialog = [FBSDKShareDialog new];
[shareDialog setMode:FBSDKShareDialogModeAutomatic];
// [FBSDKShareDialog showFromViewController:self.messageTableViewController withContent:content delegate:self];
[shareDialog setShareContent:content];
[shareDialog setDelegate:self];
[shareDialog setFromViewController:self.messageTableViewController];
[shareDialog show];
}
Delegate methods below are not working. Meaning after the post is complete, I can see it on the FB account, but none of these delegate methods execute.
#pragma mark - delegate methods
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results {
// if ([sharer isEqual:self.shareDialog]) {
NSLog(#"I'm going to go crazy if this doesn't work.%#",results);
// Your delegate code
// }
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
NSLog(#"sharing error:%#", error);
NSString *message = error.userInfo[FBSDKErrorLocalizedDescriptionKey] ?:
#"There was a problem sharing, please try again later.";
NSString *title = error.userInfo[FBSDKErrorLocalizedTitleKey] ?: #"Oops!";
[[[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer
{
NSLog(#"share cancelled");
}
Console output:
The only message I get back after posting is after a few seconds this message appears:
plugin com.apple.share.Facebook.post invalidated
Please help!
Footnote: appDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Initialize Parse.
[Parse enableLocalDatastore];
[Parse setApplicationId:#"XXXX"
clientKey:#"XXX"];
[PFFacebookUtils initializeFacebookWithApplicationLaunchOptions:launchOptions];
//Initialize Facebook
[FBSDKAppEvents activateApp];
return [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
}
//Method added for facebook integration
- (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 {
// 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.
[FBSDKAppEvents activateApp];
}
I think I am too late answering this question but someone else could trap into this as well, that's why sharing my knowledge.
As per Facebook API documentation
sharer:didCompleteWithResults: Sent to the delegate when the share completes without error or cancellation.
The results from the sharer. This may be nil or empty.
its probably because this delegate method is only get called when the post is successfully shared. In case of failure the other delegate method sharer:didFailWithError:get called. I think Facebook API should not need to add the result parameter is that case.
So in my experience if sharer:didCompleteWithResults whenever this is called that would mean success.

Integrating Dropbox chooser in iOS

In my iOS app i am trying to fetch details of a file stored in dropbox on click of button.
I am trying to choose a file from dropbox and redirect back to my application using DBChooser. It works fine when a user is already logged in the Dropbox.
-(void)choose{
[[DBChooser defaultChooser] openChooserForLinkType:DBChooserLinkTypeDirect fromViewController:self
completion:^(NSArray *results)
{
if ([results count]) {
_result = results[0];
link = [NSString stringWithFormat:#"%#", _result.link];
name = _result.name;
size = [NSString stringWithFormat:#"%lld", _result.size];
icon = [NSString stringWithFormat:#"%#", _result.iconURL];
} else {
_result = nil;
[[[UIAlertView alloc] initWithTitle:#"CANCELLED" message:#"user cancelled!"
delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil]
show];
}
}];
}
Also i have following function in Appdelegate.m
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:
(NSString *)sourceApplication annotation:(id)annotation
{
if ([[DBChooser defaultChooser] handleOpenURL:url]) {
// This was a Chooser response and handleOpenURL automatically ran the
// completion block
return YES;
}
return NO;
}
Problem starts when user is not logged in and when i click on button it opens dropbox and asks me to enter credentials. After successful logged in, i am able to view my dropbox data, but i am not able to choose anything i.e. on clicking an image it should redirect me back to my aplication, instead it is opening that image in dropbox itself. This happens only when user is not logged in.
I have set the URL schemes for the DropIns used for chooser. I just need to verify if user is logged in the dropbox before calling the choose function. Please help i am stuck on this.

Action From Local Notification Opened (iOS)

I've searched other questions similar to this here and I can't find any that seem to actually work. What I'm trying to do is when the user opens the app from a local notification, I need it to execute some code (such as opening the UIMessageComposer or displaying a UIAlertView). Anyone have any idea on how I would do this? Just as a note it is a local notification not a push notification.
You need to implement this method in you AppDelegate.m file
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
You can do want you want in this.
Here's a good tutorial on how to work with Local notifications. http://www.appcoda.com/ios-programming-local-notification-tutorial/
use this
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Reminder"
message:notification.alertBody
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
// Set icon badge number to zero
application.applicationIconBadgeNumber = 0;
}

Ios Alert on first launch to set up notification

I have created a photography assignment generator app using dreamweaver/phonegap with some finishing touches in xcode.
I have set up a settings bundle where the user can set a daily reminder on on off. it is preset to OFF, as i would rather not annoy people who don't want it.
Because i have done this using dreamweaver, I can't find a way to access the settings bundle, so the user has to go to settings, flick the switch, and reboot the app to have it take effect.
What I would like to do is have the app ask them the first time the app is launched whether or not they would like to set up a daily reminder. If they tap yes, it should set the reminder setting to ON/YES, if no, it should continue on with the default set to no.
it would be even more awesome if I could have a "Maybe Later" button.
I am not great at programming, and it was a lot of work for me to get this working(thanks to help from the great folks on here and other sites on the net)
I have tried using various IF/THEN, but I can't get it to work.
So here is what I have so far...would appreciate it greatly if any of you would be able to help me figure this out.
Thank you
Noel Chenier
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOtions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound];
NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
NSDictionary *appDefaults =[NSDictionary dictionaryWithObject:#"NO" forKey:#"enableNotifications"];
[defaults registerDefaults:appDefaults];
[defaults synchronize];
UILocalNotification *localNotif= [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
NSLog(#"Recieved Notification %#",localNotif);
}
/*NSArray *keyArray = [launchOptions allKeys];
if ([launchOptions objectForKey:[keyArray objectAtIndex:0]]!=[nil)
{
NSURL *url = [launchOptions objectForKey:[keyArray objectAtIndex:0]];
self.invokeString = [url absoluteString];
}*/
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
This is a pretty simple task, especially considering you're already using NSUserDefaults. All you need to do is store a BOOL in your defaults every time the app launches. For example:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOtions:(NSDictionary *)launchOptions {
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
if(![defaults boolForKey:#"firstLaunch"]) {
//this key has never been set - this is the first launch
[defaults setBool:YES forKey:#"firstLaunch"];
//show your alert here that you only want to show on the
//first application launch
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:#"Some Title"
message:#"Some message" delegate:self cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Some Button", #"Another Button", #"One More Button",
nil];
[alert show];
}
}

Apns-alert customization

I have successfully used APNS in iphone app and still have a problem the alert customization.Below is my question:
1 I can't custom the Alert view,like title and button title.I custom the alert like:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSDictionary *apsDic = [userInfo valueForKey:#"aps"];
NSString *alertStr = [apsDic valueForKey:#"alert"];
NSNumber *badgeNum = [apsDic valueForKey:#"badge"];
NSString *soundStr = [apsDic valueForKey:#"sound"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[arr objectAtIndex:1]
message:msg
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:#"view",nil];
[alert show];
[alert release];
}
In my App, the title of the alert is my app's title;and the button titles are "Close" and "View".
2 when I click the "View", is shows the launch view of my app and then it crashes.Why?
So if the alert is provided by the system which can't be customized, the view action is also under control of system. It seems there's contradiction between 1 and 2.
Any help is appreciated!
thanks
I find: if your app does not start, the apns-alert is provided by the iOS which you can't customize.

Resources