I am implementing Twitter in my iPhone application and if the user does not have any Twitter accounts set up, I would like him to be able to open his Twitter settings from my app. Is there any way to do this in iOS 5.1?
In iOS 5.0 we could do as below but I have not managed to find a way to do this in 5.1
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=TWITTER"]];
Try this..
TWTweetComposeViewController *ctrl = [[TWTweetComposeViewController alloc] init];
if ([ctrl respondsToSelector:#selector(alertView:clickedButtonAtIndex:)]) {
// Manually invoke the alert view button handler
[(id <UIAlertViewDelegate>)ctrl alertView:nil
clickedButtonAtIndex:0];
}
[ctrl release];
I don't know the reason why but Apple has removed the settings apps URL Schemes. Yes it was working in iOS 5.0 but it doesn't work in 5.1
Related
going to app store from app using this code
NSURL *myApplicationURL = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication]openURL:myApplicationURL];
Now how can i comeback from app store to app using cancel button.
Thanks for help.
Once you exit your Application you have no way to come back automatically, the user has to open the App again.
You can use show a modal SKStoreProductViewController (available on iOS 6) to show the AppStore inside your Application.
It is easy with the SKStoreProductViewController as redent84 answered and it is introduced in iOS 6+. With that users can buy your other apps right within the application.
First add StoreKit.framework to your project and add #import to header file.
Then find the Apple id of the app by going in iTunes connect manage applications and clicking on app will show you apple id and other details and pass that to the SKStoreProductViewController.
Below is the code
#import "ViewController.h"
#import <StoreKit/SKStoreProductViewController.h>
#interface ViewController ()<SKStoreProductViewControllerDelegate>
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self showMyApps];
}
-(void)AppStoreAction:(id)sender{
NSDictionary *appParameters = [NSDictionary dictionaryWithObject:#"533886215"
forKey:SKStoreProductParameterITunesItemIdentifier];
SKStoreProductViewController *productViewController = [[SKStoreProductViewController alloc] init];
[productViewController setDelegate:self];
[productViewController loadProductWithParameters:appParameters
completionBlock:^(BOOL result, NSError *error)
{
}];
[self presentViewController:productViewController
animated:YES
completion:nil];
}
-(void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
{
[self dismissViewControllerAnimated:YES completion:nil];
}
#end
In earlier versions you could link to the App Store: [[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://itunes.apple.com/de/artist/apple/id284417353?mt=12"]] but with this once you exit app you cannot go back to your app.
But with this SKProductViewController you can hit cancel button and go back to your app.
Hope it helps.
try this ........You can use a URL scheme if you have control of the web page. Simply add a link using your scheme.
If your scheme is myapp: then:
Return to the app
See this site for a tutorial. http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-working-with-url-schemes/ refer:Return back to iPhone app from safari
Looks like iOS 5.1 has broken the standard URL encoding for navigating a user to a Preference.
For example:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=TWITTER"]];
Works in iOS 5.0 but not in iOS 5.1 (both device and simulator).
Has anyone found a way to replicate this functionality in iOS 5.1?
It is little tricky , i get by the removing the subviews in *TWTWeetComposeViewController*, so it shows only alert when user is not loged in and by the clicking on setting button , we can open Setting page in my app.
+ (void)setAlertForSettingPage :(id)delegate
{
// Set up the built-in twitter composition view controller.
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
// Create the completion handler block.
[tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
[delegate dismissModalViewControllerAnimated:YES];
}];
// Present the tweet composition view controller modally.
[delegate presentModalViewController:tweetViewController animated:YES];
//tweetViewController.view.hidden = YES;
for (UIView *view in tweetViewController.view.subviews){
[view removeFromSuperview];
}
}
here , delegate is your viewcontroller , if you are using this method inside your viewcontroller just use self instead of delegate.
EDIT: If you get any deprecated errors, use the following iOS6 compatible code instead:
- (void)setAlertForSettingPage
{
// Set up the built-in twitter composition view controller.
SLComposeViewController *tweetViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
// Present the tweet composition view controller modally.
[self presentViewController:tweetViewController animated:YES completion:nil];
for (UIView *view in tweetViewController.view.subviews){
[view removeFromSuperview];
}
}
No I don’t know a way to replicate this functionality.
But what you can do is file a Radar requesting the restoration. Here is a radar requesting that the schemes be documented in the first place.
David Barnard has confirmed that iOS 5.1 breaks the settings apps URL schemes.
Update: iOS 8 has similar functionality for opening your app’s settings. Thanks Apple, Mike and Soto_iGhost.
The constant UIApplicationOpenSettingsURLString (UIApplication Documentation) will open the settings for your app and not, say Twitter’s settings. Not exactly the same functionality but much cleaner than before and now officially recognized.
This should be extra useful now that each app has a place in Settings for using privacy, cellular data, background app refresh and notifications.
you can do this.
TWTweetComposeViewController *ctrl = [[TWTweetComposeViewController alloc] init];
if ([ctrl respondsToSelector:#selector(alertView:clickedButtonAtIndex:)]) {
// Manually invoke the alert view button handler
[(id <UIAlertViewDelegate>)ctrl alertView:nil
clickedButtonAtIndex:0];
}
If you look in Twitter's framework (that Twitter view controller), it has "prefs:root=TWITTER" inside, 5.1 also has this line. So probably Apple made something to disable it for other apps, like some special key in plist or method "openURL" somehow checks if it's not a system app.
i have this idiotic Question .
Is there any way open an another ios Application inside a view controller of a app.
I know we can open a another Ios app if we have url schema and the calling application goes to background and called application goes to background.
Is there any way ?? i just got a dream ,so am asking can we do it??
It is not possible to do it with the iPhone SDK. You can do this though by using Private APIs.
You can make it work on jailbroken devices.
But if you want to call native social apps like facebook or twitter you should use this code.
It works and apple approves it.
NSURL *fbNativeAppURL = [NSURL URLWithString:#"fb://"];
if ( [[UIApplication sharedApplication] canOpenURL:fbNativeAppURL])
{
[[UIApplication sharedApplication] openURL:fbNativeAppURL];
}
or
NSURL *twNativeAppURL = [NSURL URLWithString:#"twitter://"];
if ( [[UIApplication sharedApplication] canOpenURL:twNativeAppURL])
{
[[UIApplication sharedApplication] openURL:twNativeAppURL];
}
At one point in my app, I would like to redirect the user to the official Settings app. If possible, I also want go straight to the Network section within the Settings app.
I think what I need is the Settings app's url scheme and the format to construct my request. But I doubt that calling such an official app is forbidden.
Can anyone can help me?
As noted in the comments below, this is no longer possible in iOS version 5.1 and after.
If you are on iOS 5.0, the following applies:
This is now possible in iOS 5 using the 'prefs:' url scheme. It works from a web page or from an app.
example urls:
prefs:root=General
prefs:root=General&path=Network
sample usage:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=General"]]
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=General&path=Network"]]
From IOS 8 you can call the settings from within app with this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
It's also work in iOS version > 5.1, but you must add an URL schemes in URL types in Xcode:
Then you can use
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=WIFI"]];
It's can open system WiFi setting
now.
Other path please find in this answer: iOS Launching Settings -> Restrictions URL Scheme.
Bad news: As #Hlung and #jasongregori suggested, for iDevices whose OS version >= iOS 5.1 && < iOS 8.0, there is once again NO official/documented way to call the built-in Settings app from a third-party app. Period.
Calling the settings app from other app is possible only from iOS 8. So, use the following code
if([CLLocationManager locationServicesEnabled]&&
[CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied)
{
//...Location service is enabled
}
else
{
if([[[UIDevice currentDevice] systemVersion] floatValue]<8.0)
{
UIAlertView* curr1=[[UIAlertView alloc] initWithTitle:#"This app does not have access to Location service" message:#"You can enable access in Settings->Privacy->Location->Location Services" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[curr1 show];
}
else
{
UIAlertView* curr2=[[UIAlertView alloc] initWithTitle:#"This app does not have access to Location service" message:#"You can enable access in Settings->Privacy->Location->Location Services" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Settings", nil];
curr2.tag=121;
[curr2 show];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag == 121 && buttonIndex == 1)
{
//code for opening settings app in iOS 8
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
}
from iOS 8, you can redirect with
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
enjoy coding
Just an additional answer to add onto the one's addressing iOS8+. If you're supporting anything below 8, you should check to see if it's supported
BOOL canGoToSettings = (UIApplicationOpenSettingsURLString != NULL);
if (canGoToSettings)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
For settings in iOS 9 this is worked for me.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=Settings"]];
But make sure you add a url schemes in URL types in
Info tab in app targets.
For iOS 10 you can use:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"App-Prefs:root=Settings"]];
It is also working on iOS 9!
In my iPhone app, I need to access the SMS application.
I need that when I click a button in my iphone app. It should open the SMS app of iphone and preload the message body with the text that I specify in my app.
How can we access the SMS API from iPhone app?
What should be done?
This is possible starting from iOS 4.0; use the MFMessageComposeViewController from the MessageUI Framework.
Details and example: http://developer.apple.com/library/ios/#samplecode/MessageComposer/Introduction/Intro.html
Try this :
MFMessageComposeViewController *pickerSMS = [[MFMessageComposeViewController alloc] init];
pickerSMS.messageComposeDelegate = self;
pickerSMS.body = #"hello!";
[self presentModalViewController:pickerSMS animated:YES];
[pickerSMS release];