my app that share image on Facebook. that work fine but i want to disable user inter face with post. So user can`t modify My initialText is this possible ?
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *fbComposer = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbComposer setInitialText:#"Yes U Are?"];
if ([fbComposer addImage:[UIImage imageWithData:[Array objectAtIndex:i]]]) {
}
[self presentViewController:fbComposer animated:YES completion:nil];
}else {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Facebook Error"
message:#"You may not have set up facebook service on your device or\n You may not connected to internent.\nPlease check ..."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alertView show];
}
}
hear is the image of Facebook share i want to only click on post btn And Cancle btn .So user can only Post.
Related
so I have my app setup with share action button that shares the current URL to Twitter or Facebook however when I click the Facebook button it shows a Twiiter share sheet. The (Tiwtter option works fine)
After I click the FACEBOOK option, when testing on iPhone the standard twiiter share sheet appears.
- (IBAction)social:(id)sender {
UIActionSheet *share = [[UIActionSheet alloc] initWithTitle:#"Pass on the news!" delegate:self cancelButtonTitle:#"OK" destructiveButtonTitle:nil otherButtonTitles:#"Post to Twitter", #"Post to Facebook", nil];
//You must show the action sheet for the user to see it.
[share showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
//Each button title we gave to our action sheet is given a tag starting with 0.
if (actionSheet.tag == 0) {
//Check Twitter accessibility and at least one account is setup.
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *tweetSheet =[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet addURL:self.newsItemWebView.request.URL]; //This is setting the initial text for our share card.
[tweetSheet setInitialText:#"Check out this article I found using the 'Pass' iPhone app:, "];
//Brings up the little share card with the test we have pre defind.
[self presentViewController:tweetSheet animated:YES completion:nil];
} else {
//This alreat tells the user that they can't use built in socal interegration and why they can't.
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"You can't send a tweet right now, make sure you have at least one Twitter account setup and your device is using iOS6 or above!." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
} else if (actionSheet.tag == 1) {
//Check Facebook accessibility and at least one account is setup.
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *facebookSheet =[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebookSheet addURL:self.newsItemWebView.request.URL];
//This is setting the initial text for our share card.
[facebookSheet setInitialText:#"Check out this article I found using the 'Pass' iPhone app:"];
//Brings up the little share card with the test we have pre defind.
[self presentViewController:facebookSheet animated:YES completion:nil];
} else {
//This alreat tells the user that they can't use built in socal interegration and why they can't.
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"You can't post a Facebook post right now, make sure you have at least one Facebook account setup and your device is using iOS6 or above!." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
}
}
You are using actionSheet.tag which will be the same for the entiere actionsheet.
If you want to know which button is pressed you should use buttonIndex in your if statements.
Even better is to use UIActivityViewController.
NSArray *items = #[self.newsItemWebView.request.URL];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
activityViewController.completionHandler = ^(NSString *activityType, BOOL completed) {
// do any thing you want when the user finishes the share activity.
// Like present a message that that activity has completed or not.
};
[self presentViewController:activityViewController animated:YES completion:nil];
I'm working on a twitter app and i want to immediately display tweet after sending. I tried to use reloadData, but it didn't work. Can anyone help me? Thank you!
Here's my code:
- (IBAction)postNewTweet:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#""];
[self presentViewController:tweetSheet animated:YES completion:nil];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tweetTableView reloadData];
});
}
else
{
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Sorry"
message:#"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
Blaze, you are reloading the table view right after presenting the compose sheet, so it reload the table right there - and you are passing the completion block as nil, so nothing will happen when user finishes tweeting.
Also, you need to be sure that you are reloading not only the table, but the array or any other object that is the source of tweetTableView.
For example:
When calling the tweet compose sheet:
[self presentViewController:tweetSheet animated:YES completion:^(SLComposeViewControllerResult result)
{
dispatch_async(dispatch_get_main_queue(), ^{
[self reloadTweets];
});
}];
And then, you reload the tweets source and only then the table
-(void)reloadTweets
{
tweetsArray = .... //load the tweets from the internet, and only then reload the table
[self.tweetTableView reloadData];
}
I just want to know how to prevent my alert view from appearing everytime I open my application that's already connected to the internet. I'm using ARC if that helps.
This is the code I have in my didFinishLaunchingWithOptions method inside my AppDelegate:
__weak id myself = self; // to silence warning for retain cycle
_httpClient = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:#"http://apple.com"]];
[_httpClient setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusNotReachable:
{
// Not reachable
NSLog(#"Not connected to the internet");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:#"Not connected to the internet" delegate:myself cancelButtonTitle:nil otherButtonTitles:#"Dismiss", nil];
[alert show];
break;
}
case AFNetworkReachabilityStatusReachableViaWiFi:
{
NSLog(#"Connected to the internet via WiFi");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:#"Connected to the internet via WiFi" delegate:myself cancelButtonTitle:nil otherButtonTitles:#"Dismiss", nil];
[alert show];
break;
}
case AFNetworkReachabilityStatusReachableViaWWAN:
{
NSLog(#"Connected to the internet via WWAN");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:#"Connected to the internet" delegate:myself cancelButtonTitle:nil otherButtonTitles:#"Dismiss", nil];
[alert show];
break;
}
default:
break;
}
}];
Echoing #D80Buckeye: just don't pop an alert for reachability. It's completely unnecessary, and doesn't add anything to the user experience (it's not like the user can do anything to fix a lack of reachability like that). If anything, you could show a non-modal indication of network reachability.
How about creating a global flag
static BOOL g_FirstTime = YES;
and check it before displaying alert view
if (g_FirstTime) {
g_FirstTime = NO;
break;
}
NSLog(#"Connected to the internet via WiFi");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:#"Connected to the internet via WiFi" delegate:myself cancelButtonTitle:nil otherButtonTitles:#"Dismiss", nil];
[alert show];
break;
Without knowing the scope of your project it's hard to make a solid suggestion. My whole-hearted suggestion is that you do NOT want to do a pop-up every time the end user bounces back on the network. If you have code implemented that is reliably detecting a refreshed network connection, if I were you, I would put some sort of subtle (but obvious) on-screen indicator like a small icon/image or maybe even a UILabel that says "connected" or "disconnected" or whatever verbiage works for you. As others have suggested I would completely steer clear of instantiating a pop-up of any sort for that alert.
Regarding the code itself - get very familiar with View Controller Programming and iOS App Programming Guide. Between those two documents you can properly map out how to detect and react to when your app comes in and out of the background state, when it launches, when it becomes active, when your views appear/load, etc. Combine those methods & calls with some global state-driven variables and you should be well on your way.
Bottom line is you want to get familiar with those app state documents as well as [[NSNotificationCenter defaultCenter] addObserver:<#(id)#> selector:<#(SEL)#> name:<#(NSString *)#> object:<#(id)#>]
Let me know if that doesn't make sense.
Can anyone tell me how i can add text in TweetSheet when an UIAlert Title button is pressed?
Currently i am using this code to achieve it, but failed so far.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init];
if ([title isEqualToString:#"Add custom text"]) {
UIAlertView *alert= [[UIAlertView alloc] initWithTitle:#"Add a template" message:nil delegate:self cancelButtonTitle:#"Hi it was nice meeting you" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
if ([title isEqualToString:#"Hi it was nice meeting you"]) {
[tweetSheet setInitialText:#"hey it was nice meeting you"];
}
}
Can anyone tell me what's wrong here?
You're not presenting your TWTweetComposeViewController you can do this simply by adding :
[self presentModalViewController:tweetSheet animated:YES];
I guess this code is only for a simple test tweet.
For a serious project you should always:
Check if the user can send tweets by calling +(BOOL)canSendTweet before trying to show the TWTweetComposeViewController
If not sure about the properties you'll be setting (text, images, urls), you need to check if adding them was successful : -(BOOL)addImage:(UIImage *)image, -(BOOL)addURL:(NSURL *)url and -(BOOL)setInitialText:(NSString *)text all return YES if it was successful and NO if not.
You can set a completion handler to perform different actions depending on what the user decided (send tweet/cancel)
The WWDC session about Twitter integration from 2011 is very simple and detailed, you should watch it and read the documentation if you need more information.
i have an IBAction which does some processing and within will have a few UIAlertViews (to show alerts). However it seems that the FIRST alert in the paragraph is being called TWICE (once immediately after i clicked and another time after all the other alerts has occured). Additionally, the first time the alert appears, the alert automatically closes even though i have an OK button and the user has not clicked on it. The 2nd time the alert appears, it will require the user to click on OK.
I tried moving the paragraph out from IBAction into its own function but still the problem occurs.
all the alerts in my IBAction/function are the same:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"blah" message:#"blah" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil,nil];
[alert show];
[alert release];
but the other alerts function normally.
the code looks like this ("blah" is the one being called twice):
-(void)function {
if (......) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"blah" message:#"blah" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil,nil];
[alert show];
[alert release];
for (int i=0; i<2; i++) {
if (.....) {
//do stuff
} else {
UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:#"blah2" message:#"blah2" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil,nil];
[alert2 show];
[alert2 release];
}
}
} else {
UIAlertView *alert3 = [[UIAlertView alloc] initWithTitle:#"blah3" message:#"blah3" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil,nil];
[alert3 show];
[alert3 release];
}
}
please help!
First of all, we need more code to diagnose your problem. What you provide is not sufficient.
Second, I once encountered a similar problem: when a compose an email action is triggered by the user who didn't set up her email account on that device, I asked my app to show an UIAlertView. However, when I tested my code on a real device with such a scenario, two consecutive UIAlertViews showed, one after another, both of which are about the email account not set up issue.
I finally figured out that the iOS system will automatically show an UIAlertView when the email account is not set up while a user tries to compose an email, which is why two UIAlertViews showed up when I only expected one.
Hope that helps.