I am making a twitter application for iPhone, I am trying to add a button which will open Safari, and take the user to their twitter homepage. I have a textfield called username, so the following code does not work, hopefully someone will be able to help me out.
-(IBAction)viewAccount {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.twitter.com/", username.text]];
}
Any help is appreciated! Thank you!
Try this
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://www.twitter.com/%#", username.text]]];
Check if your URL is correct
NSURL* twitterURL = [NSURL URLWithString:#"http://www.twitter.com/", username.text];
NSLog(#"my twitter url: %#", twitterURL);
edit: seems someone was faster than me ;)
Related
I was using in my app this link to user review:
- (IBAction)rateMyApp:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"itms-apps://itunes.apple.com/app/881623474"]];
the openURL is deprecated so now it is using according to the developer website this one:
- (IBAction)rateMyApp:(id)sender {
[[UIApplication sharedApplication] openURL:<#(nonnull NSURL *)#> options:<#(nonnull NSDictionary<NSString *,id> *)#> completionHandler:<#^(BOOL success)completion#>]];
But I can not make it work any help is more than welcome.
thanks in advance
Did you check in real iPhone/iPad? In simulator this not works. In device it works. If not works then make sure you return YES in openURL function in AppDelegate class.
- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation
{
return YES;
}
I need to open the bluetooth settings menu in IOS10 and above.But [[UIApplication sharedApplication] openURL:
[NSURL URLWithString:#"prefs:root=Bluetooth"]]; is not working in ios 10.
After exploring multiple document I got below link which provide code which will work properly. https://gist.github.com/johnny77221/bcaa5384a242b64bfd0b8a715f48e69f
But, Now I have question will app store accept this patch code or they will reject application.
Please help me to solve this issue.
Thanks in advance
Swift 3.0:- Working in all iOS version upto iOS 10.2
let url = URL(string: "App-Prefs:root") //for system setting app
#IBAction func blutootheButtonTapped(_ sender: AnyObject) {
let url = URL(string: "App-Prefs:root=Bluetooth") //for bluetooth setting
let app = UIApplication.shared
app.openURL(url!)
}
As of iOS 10 "App-Prefs:root" should be used rather than "prefs:root". See below Objective C code. Tested this , code works fine but Apple may reject the app because of this.
NSString *settingsUrl= #"App-Prefs:root=Bluetooth";
if ([[UIApplication sharedApplication] respondsToSelector:#selector(openURL:options:completionHandler:)]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:settingsUrl] options:#{} completionHandler:^(BOOL success) {
NSLog(#"URL opened");
}];
}
I am working with xcode and I'm stuck in writing URL links. I want the user to fill the rest of my written URL code.
Here's the code:
- (IBAction)openURL:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://facebook.com/....."]];
}
The user will see this:
facebook.com/write your address here...
The "facebook.com/" part is a label and the "write your address here..." a textfield that is filled in the apps settings. For example I can write "JJMLS" in settings, so the result is "facebook.com/JJMLS".
I have sat a custom/invisibile "openURL" button over the result area.
How can I tell xcode that #"http://facebook.com/(.....)" part is an area that should get the JJMLS result when the user fills it???
I will really appreciate some help!
-JJ
Try something like this:
- (IBAction)openURL:(id)sender {
if(textfield.text == nil){
UIAlertView *noTextAlert = [UIAlertView initWithTitle: #"No text entered!"
message: #"Please enter some text"
delegate: self
cancelButtonTitle: #"Ok"
otherButtonTitles: nil];
[noTextAlert show];
}
else{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://facebook.com/%#", textfield.text]]];
}
}
If you have any questions about the code, just put it in the comments. Hope this helps!
FIXED — Ok, found what it was, there was an errant [[UIApplication sharedApplication] cancelAllLocalNotifications]; being fired when I wasn't expecting it.
Well there's your problem.
Thanks for the help everyone, sorry to have it turn out to just be dumb coder syndrome.
I've built out my local notification like so:
- (void)scheduleNotification {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
Class cls = NSClassFromString(#"UILocalNotification");
if (cls != nil) {
UILocalNotification *notif = [[cls alloc] init];
NSLog(#"%#", [NSDate date]);
notif.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
notif.alertBody = NSLocalizedString(#"Hello.", nil);
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
NSLog(#"Notification scheduled at %#", notif.fireDate);
[notif release];
}
}
As expected my debug log outputs the correct fireDate 10 seconds in the future. If I don't leave my app I get a successful application:didReceiveLocalNotification: callback.
The hiccup here is if I push the button to schedule this notification and hit the home button to put it in the background. If I do this, the notification never fires and I never get an alert view from the OS.
Did I miss something obvious here? I've looked up and down here and the Apple docs and feel I've missed something obvious.
Any help would be greatly appreciated. Thanks.
See the example in Apple's docs:
http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW1
Could it be that not setting timeZone to [NSTimeZone defaultTimeZone] is causing the problem? GMT is assumed if timeZone isn't set (nil default).
Have you tried wrapping the code in a background task?
Ok, found what it was, there was an errant [[UIApplication sharedApplication] cancelAllLocalNotifications]; being sent when entering the background.
Is there a way to open the app store to a specific application?
I tried using something like the following:
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:#"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284417350&mt=8&uo=6"]];
But got the following: "Safari cannot open the page because to many redirects occurred".
Apparently this issue only affects the simulator. A build an go on the device works perfect.
Use http://itunes.com/app/YourAppNameWithoutSpaces
See also this.
Another simple way is:
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:#"itms-apps://itunes.com/app/YourAppNameWithoutSpaces"]];
This is very clean
You can open app without opening safari
NSString *appId = #"you appid"; //like 999999999
NSString *link = [#"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=" stringByAppendingString:appId];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:link]];
Replace iTunesLink with your App URL.
NSString *iTunesLink = #"https://itunes.apple.com/us/app/digital-speedometer-pro/id1021728349?mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
Starting from iOS 6 right way to go is using SKStoreProductViewController class.
Code is here: https://stackoverflow.com/a/32008404/1151916