How can i launch the twitter settings on the Device from my app with objective-c?
I am working on an app that shares a link on twitter, i am using the SLComposeViewController and it works, but when the Twitter app is not installed and no Twitter account is configured on settings it does nothing.
I want to show an alert inviting the user to log in on twitter to be able to share the link, when the user taps on a button the app should launch the Twitter settings on the device.
I have been reading that using the url scheme like this is not allowed since iOS 5.1
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=TWITTER"]];
I read it is only allowed to launch your app settings with this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
But i have found in some apps that it actually opens the Twitter settings like this one:
screenshot of meme generator app that opens twitter settings
Do you know how to do this?
Here is the code i use for the SLComposeViewController:
- (IBAction)twitterAction:(id)sender {
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityView.center=self.view.center;
[activityView startAnimating];
[self.view addSubview:activityView];
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *composerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[composerSheet setInitialText:#"text to post"];
[composerSheet addURL:[NSURL URLWithString:#"http://urltoshare.com"]];
[composerSheet addImage:[UIImage imageNamed:#"postimage.JPG"]];
[composerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
[activityView stopAnimating];
switch (result) {
case SLComposeViewControllerResultCancelled:
NSLog(#"Post Canceled");
// some code ...
break;
case SLComposeViewControllerResultDone:
[self changeSharedStatus];
NSLog(#"Post Sucessful");
// some code ...
break;
default:
break;
}
}];
[self presentViewController:composerSheet animated:YES completion:nil];
}else {
/* code to show the alert that invites the user to open settings */
}
}
Why the app that you found opens the Twitter settings,
it's because when you ask iOS to "create" a tweet, if there is no account setup in iOS, iOS will show you up this alertview asking you if you want to go in the setting for adding a twitter account to iOS.
So if you call SLComposeViewController the code is going to trigger this alertview if there is no twitter account in iOS:
SLComposeViewController *controllerSLC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[controllerSLC setInitialText:#"text"];
[self presentViewController:controllerSLC animated:YES completion:nil];
Related
Our team manager has proposed the following idea: within our app, when a user taps a Send Msg button, our app opens up the Messages app. Our manager wants to tap Cancel to go back to our app (see screenshot below), instead of the top left Go back to ... shortcut in the status bar. Is that possible?
This is the picture:
UPDATE The messageComposeViewController delegate method is like this, and I see some shaking when I dismiss the message controller?:****
#pragma mark - sms delegate
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result {
switch (result)
{
case MessageComposeResultCancelled:
break;
case MessageComposeResultSent:
break;
case MessageComposeResultFailed:
[LMLSendResultAlert showSuccessOrFail:0 withSuccesString:#"" andFailStr:#"短信发送失败" needPopOrdismiss:0 complete:nil];
break;
default:
break;
}
[controller dismissViewControllerAnimated:YES completion:NULL];
}
This is my viewWillAppear method:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setHidden:YES];
}
If you are opening the message editor externally, that is, you just open the default Message app (I guess this is what is happening, otherwise there wouldn't be the Back button at top left corner), unfortunately I'm not aware of any way to go back to your app when clicking the Cancel button.
However, if you are using MFMessageComposeViewController, which probably is a good idea as your users don't have to leave your app, it would be definitely possible to act accordingly when users choose to cancel.
You can take a look at Apple's doc here, which utilizes mailComposeController:didFinishWithResult:error:
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result {
// Check the result or perform other tasks.
// Dismiss the mail compose view controller.
[self dismissViewControllerAnimated:YES completion:nil];
}
Following what Stephenye has said, if you use MFMessageComposeViewController the cancel button will allow you to go back to your app (you will still be in your app anyway because you present the message controller as you present any other view controller).
Here is an example:
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result)
{
[controller dismissViewControllerAnimated:YES completion:^{
case MessageComposeResultCancelled:
break;
case MessageComposeResultFailed:
[LMLSendResultAlert showSuccessOrFail:0 withSuccesString:#"" andFailStr:#"短信发送失败" needPopOrdismiss:0 complete:nil];
break;
case MessageComposeResultSent:
break;
default:
break;
}
}];
}
-(void)presentMessagerOnViewController:(UIViewController*)controller
{
if(![MFMessageComposeViewController canSendText])
{
//show error message
return;
}
NSArray *recipients = #[#"0424456654"];
NSString *defaulMessage = #"You should absolutely upvote my answer";
MFMessageComposeViewController *composer = [[MFMessageComposeViewController alloc] init];
composer.messageComposeDelegate = self;
[composer setRecipients: recipients];
[composer setBody: defaulMessage];
[self presentViewController: composer animated:YES completion: NULL];
}
I'm trying to post image and text to twitter. On iOS7,8 the following code works well. but only on iOS6, send button is disable. When I try to send only text, send button become enable. Only when I try to send image, send button is disable. I have to support iOS6,7,8. I have no idea why It dose not work on only iOS6 and image. Someone know the reason or had know the same trouble as this?
Please advise me.
We found this problem on the iPhone4s that's iOSversion is 6.1.3.
SLComposeViewController *twvc= [SLComposeViewController composeViewControllerForServiceType:type];
[twvc setInitialText:#"a"];
if([twvc addImage:[UIImage imageNamed:#"x.jpg"]]){
NSLog(#"IMAGE IS OK");
}else{
NSLog(#"IMAGE IS NG");
}
[twvc addURL:[NSURL URLWithString:#"http://rara"]];
[twvc setCompletionHandler:^(SLComposeViewControllerResult result){
// 結果判定
switch (result) {
case SLComposeViewControllerResultDone:
break;
case SLComposeViewControllerResultCancelled:
break;
default:
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}];
[self presentViewController:twvc animated:YES completion:nil];
I am trying to give "bonus points" for users who either tweet my advertisement message or post my advertisement message on Facebook. How can I detect if...
1) The user actually pressed the post button (this way I can give them the bonus points in app)?
2) The user did not change any text in the message box (my advertisement)?
On a side note, is it possible to make the message box for these un-editable? Here is my code to actually present the message to post each:
- (IBAction)tweetButtonPressed:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"My advertisement message goes here."];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Twitter Connection Failed"
message:#"Make sure your device has an internet connection and you are connected to Twitter through your iPhone settings."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
- (IBAction)facebookPostButtonPressed:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:#"My advertisement message goes here."];
[self presentViewController:controller animated:YES completion:nil];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Facebook Connection Failed"
message:#"Make sure your device has an internet connection and you are connected to Facebook through your iPhone settings."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
You can use compliton hander to know if he press the post button, however you can't know what the content of the post.
If you realy want to you need to implement facebook yourself than you can even check the privecy of the post.
I say this because when a app ask me to post I always do it as "Private" so no one see but I still get the "Bonus".
Apple Docs
Possible values for the result parameter of the completionHandler property.
Declaration
OBJECTIVE-C
typedef NS_ENUM (NSInteger,
SLComposeViewControllerResult ) {
SLComposeViewControllerResultCancelled,
SLComposeViewControllerResultDone
};
Constants
SLComposeViewControllerResultCancelled
The view controller is dismissed without sending the post. For example, the user selects Cancel or the account is not available.
Available in iOS 6.0 and later.
SLComposeViewControllerResultDone
The view controller is dismissed and the message is being sent in the background. This occurs when the user selects Done.
Available in iOS 6.0 and later.
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Reference/SLComposeViewController_Class/#//apple_ref/c/tdef/SLComposeViewControllerResult
I am trying to implement Twitter and Facebook into my app. Therefor I am using the integrated method in iOS, which is available since iOS 6, to do this. Under iOS 6, if there is no Facebook or Twitter configured an alarm view comes up to inform the user that he has to configure an account first to use Twitter or Facebook. The alarm view gives the user the option to jump directly to the settings of Twitter or Facebook. In iOS 7, if there is no account configured, no alarm view comes up to inform the user. Seems that has been disabled under iOS 7. So I am now inform the user myself but is there a way to point the user directly to the settings like it was under iOS 6? Or do I need to change my code under iOS 7 to get the alarm back?
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"Hello a Tweet"];
[self presentViewController:tweetSheet animated:YES completion:nil];
} else {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
//inform the user that no account is configured with alarm view.
}
}
Just remove this line from your code and it will work correctly
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
in ios 7, Try with removing this condition, it will tells user to if there is no account configured.
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"Hello a Tweet"];
[self presentViewController:tweetSheet animated:YES completion:nil];
} else {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{ SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"Hello a Tweet"];
[self presentViewController:tweetSheet animated:YES completion:nil];
//inform the user that no account is configured with alarm view.
}
}
I have a free version of app. And there is a link to a full version in free app.
The link works fine in iOS 6. But in iOS 7 it shows a blank page.
Any help is appreciated!
The link I use:
- (void) getFull
{
[self hideAnimated];
NSString *iTunesLink = #"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=604760686&mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
}
Pretty strange link you are using. I use:
http://itunes.apple.com/app/id<APP_ID>?mt=8
and everything works...
In apps supporting iOS6 and above, I suggest furthermore the use of StoreKit, so you can display your app page in the App Store without leaving your app. You can do that like this:
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
{
[viewController dismissViewControllerAnimated:YES completion:nil];
}
- (void)showAppWithIdentifier:(NSNumber *)identifier
{
if ([SKStoreProductViewController class]) {
SKStoreProductViewController *controller = [[SKStoreProductViewController alloc] init];
controller.delegate = self;
[controller loadProductWithParameters:#{ SKStoreProductParameterITunesItemIdentifier : identifier }
completionBlock:NULL];
[self presentViewController:controller animated:YES completion:nil];
return;
}
// Fall back to opening App Store for iOS 5.
... open the link as you are already doing
}
Try this one, it's the new syntax with iOS 7 and replace APP_ID by your application's AppID.
itms-apps://itunes.apple.com/app/idAPP_ID
You can refer to this link and this one for more information and discussion about that.