Trying to add facebook native like button to my app. its only opening my page then after tapping ok or unlike its opening facebook homepage instead of coming back to the applciation
FBSDKLikeControl *likeButton = [[FBSDKLikeControl alloc] init];
[likeButton addTarget:self action:#selector(likeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
likeButton.objectID = #"https://www.facebook.com/a2zTwoWheels/";
likeButton.center = self.view.center;
[fbPopupView addSubview:likeButton];
Please don't suggest existing questions with callback solutions , tried all before posting this question
Related
I have a webView in my app that works well. In order to enable the user to go back to the previous url link I have a custom back button in my navigationBar. Linked to that button is a simple code line that takes the user back to the previous screen:
-(void)webBackButton {
NSLog(#"BACK BACK BACK");
[_webView goBack];
}
Works great. Now the real issue here is that there obviously shouldn't be a back button in the initial webView (there's no place to go back to). So, I would like to hide and disable the button on the first webView shown. For that to happen I guess I need to somehow check to see that the current webView is not the initial webView. Like this:
if(!_webView.URL.absoluteURL) {
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:self action:#selector(webBackButton)];
}
And I suppose this check has to be done every time the ´webViewchange itsurlpath; that is when the user uses alink. If the currentwebViewis_webView.URL.absoluteURLthe backbutton` should be hidden, otherwise it should be shown.
How do I accomplish this. As far as I understand, the delegate webViewDidFinishLoad is deprecated. I have tried using observeValueForKeyPath but it doesn't seem to trigger when I go to another url. Is there an easier way to hide the back button on the initial screen?
UIWebview Class
open var canGoBack: Bool { get }
WKWebView Class
/** #abstract A Boolean value indicating whether there is a back item in
the back-forward list that can be navigated to.
#discussion #link WKWebView #/link is key-value observing (KVO) compliant
for this property.
#seealso backForwardList.
*/
open var canGoBack: Bool { get }
Add a check on webBackButton Method :
if([self.webView canGoBack]) {
[backBtn setEnabled:YES];
} else {
[backBtn setEnabled:NO];
}
Sorry for mixing up Swift & Objective C, the pseudocode remains the same.
Sorry I am a little bit new on iOS Development , for a project i need to use popup list menu library ( i know iOS support PickerView , ... for the purpose of choosing from a list menu) but i need to use that popup list , so after some search i find this library :
https://github.com/kolyvan/kxmenu
Which i have seen the example on that project. I added same as kxmenu Example to my project and it works , but I need a slight change. Instead of clicking on Button (in the example) to open the popup menu , i want whenever user click inside UITextField , would open the popup menu.
The buttons are added as subview by this example , but i need to connect an action to the UITextField which is not written programatically (it's not added by adding subview...)
here is the code (of Example) that I really Appreciate if someone tell me what changes do i need to apply to the following code , to make this changes:
instead of using the button , Use UITextfield , I mean when user click on The UITextField it would open the kxmenu popup
please consider that in the kxmenu example , Button are added programatically , but the UITextField that i have is a property.
here is the part of the source code:
//#part 1 {
_btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
_btn1.frame = CGRectMake(5, 5, 100, 50);
[_btn1 setTitle:#"click Me" forState:UIControlStateNormal];
[_btn1 addTarget:self action:#selector(showMenu:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_btn1];
//#part 1 }
- (void) pushMenuItem:(id)sender
{
NSLog(#"%#", sender);
}
//#part 2 {
- (void)showMenu:(UIButton *)sender
//#part 2 }
{
NSArray *menuItems =
#[
[KxMenuItem menuItem:#"ACTION MENU 1234456"
image:nil
target:nil
action:NULL],
[KxMenuItem menuItem:#"Reload page"
image:[UIImage imageNamed:#"reload"]
target:self
action:#selector(pushMenuItem:)],
[KxMenuItem menuItem:#"Search"
image:[UIImage imageNamed:#"search_icon"]
target:self
action:#selector(pushMenuItem:)],
];
KxMenuItem *first = menuItems[0];
first.foreColor = [UIColor colorWithRed:47/255.0f green:112/255.0f blue:225/255.0f alpha:1.0];
first.alignment = NSTextAlignmentCenter;
[KxMenu showMenuInView:self.view
fromRect:sender.frame
menuItems:menuItems];
}
With My Slight iOS Knowledge i think these changes might apply (but i have tried that and it won't work with UITextField
instead of //#part 1 shwon in above code , i need to replace it with :
[currentTextField addTarget:self action:#selector(showMenu:) forControlEvents:UIControlEventTouchUpInside];
instead of UIButton as declaration of argument of sender in //#part 2 shwon in above code , i need to change it UITextField as argument of sender.
I would appreciate if someone show me by writing some code what changes do i need to apply to above source code for the following purposes. Thanks!
you can use "UITextFieldDelegate", for example:
- ( BOOL )textFieldShouldBeginEditing:( UITextField *)textField
[self taggle];
)
-(void)taggle{
NSArray *menuItems =
#[
[KxMenuItem menuItem:#"开启闪光灯"
image:nil
target:self
action:#selector(clickTorch)],
[KxMenuItem menuItem:#"翻转"
image:nil
target:self
action:#selector(clickCamera)],
[KxMenuItem menuItem:#"美颜"
image:nil
target:self
action:#selector(clickBeautyFace)],
];
[KxMenu showMenuInView:self.view
fromRect:textField.frame // UITextField *textField = [[UITextField alloc] initWithFrame:....] // you can write any frame and change it.
menuItems:menuItems];
}
Placed the Facebook like button in native app with following:
FBSDKLikeControl *button = [[FBSDKLikeControl alloc] init];
button.objectID = #"https://www.facebook.com/FacebookDevelopers";
[self.view addSubview:button];
How can we retrieve like count or is already liked status of button?
Is it possible on iOS < 6?
In iOS 6+, I can share using message composer.
What about previous version of iOS? FB SDK share uses facebook app id so it's not the way.
Maybe i can open native facebook app with scheme like fb://share/photo/[image_data]?
Any other ideas?
For iOS < 6, you can always used ShareKit plugin.
In this repository, they share nice example to share image on your fb account.
Have a look at the class ExampleShareImage:
- (void)loadView
{
[super loadView];
self.imageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"sanFran.jpg"]] autorelease];
imageView.frame = CGRectMake(0,0,self.view.bounds.size.width,self.view.bounds.size.height);
[self.view addSubview:imageView];
}
- (void)share
{
SHKItem *item = [SHKItem image:imageView.image title:#"San Francisco"];
/* optional examples
item.tags = [NSArray arrayWithObjects:#"bay bridge", #"architecture", #"california", nil];
//give a source rect in the coords of the view set with setRootViewController:
item.popOverSourceRect = [self.navigationController.toolbar convertRect:self.navigationController.toolbar.bounds toView:self.view];
*/
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
[SHK setRootViewController:self];
[actionSheet showFromToolbar:self.navigationController.toolbar];
}
You can also integrate FBConnect framework provide by Facebook.
This is the current way i'm customizing my buttons:
UIAlertView *av = [[UIAlertView alloc] init];
[av addButtonWithTitle:#""];
UIButton *yesButton = [av.subviews lastObject];
[av show];
[yesButton setImage:[UIImage imageNamed:#"test.png"] forState:UIControlStateNormal];
The problem with this is that the original view is still visible around the image I set for the button. It doesn't completely encapsulate the image. Here's an example of what I have so far:
https://www.dropbox.com/s/htb9pfihwmel5oo/testimage.png
Is there anyway to make it so that the image completely takes up the entire button?
If you wan't something that's not as robust as Sly Raskal's answer and just want a quick hack, that works similar to your existing code. You could do something like this..Of course you can change the new buttons frame to match how you want it. Also, you would have to define the UIAlertView as a variable to so you have a reference to it, and dismiss it in your someAction: method.
UIAlertView *av = [[UIAlertView alloc] init];
[av addButtonWithTitle:#""];
UIButton *yesButton = [av.subviews lastObject];
[yesButton setHidden:YES];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[av addSubview:button];
[av show];
[button setImage:[UIImage imageNamed:#"test.png"] forState:UIControlStateNormal];
[button addTarget:av action:#selector(someAction:) forControlEvents:[yesButton allControlEvents]];
[button setFrame:yesButton.frame];
If in this case all you are doing is styling the buttons to look different, but in a simple fashion, I would follow this tutorial to accomplish the effect you are looking for:
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-uialertview-custom-graphics/
If the application you are creating is destined for the App Store, I just want to also mention that whatever changes you implement, be sure it doesn't use any private API's or goes against anything documented in the HIG. Either of these circumstances is surely going to red flag your app for rejection.