I am developing a simple application which has to send an SMS message from the app itself instead of launching the native Text app.
Here's my action now. What should I change to achieve my desired functionality?
-(IBAction)startButtonPressed
{
NSString *phoneNumber = #"13136296693";
NSString *url = [NSString stringWithFormat: #"sms:%#",phoneNumber];
NSLog(#"Send SMS to: %# ", url);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}
Thanks!
Thomas
If I'm not mistaken I think sending text messages via your own application is only available in the iPhone 4.0 SDK.
Can't be done with the current SDK. I believe Apple announced that applications in iPhone OS 4.0 will be able to do this, using a similar interface to the existing MFMailComposeViewController malarkey.
Here's what apple says:
https://web.archive.org/web/20140604143837/http://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/SystemMessaging_TopicsForIOS/Articles/SendinganSMSMessage.html
Here's a tutorial fon another forum.
http://iosdevelopertips.com/core-services/how-to-send-an-sms-progammatically.html
It's still not entirely automated. The user has to tap the send button. I haven't gotten it working yet. Tell me if you have better luck. If you can think of a way for me to program my app to "tap" the send button instead of the user, let me know.
Related
When I used UIImagePickerController on ios <= 9, I didn't see any issues.
On ios 10 I got strange message. I noticed this massage appear after using any code from Photos.framework. (for example checking PHPhotoLibrary status )
Class PLBuildVersion is implemented in both
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices
(0x12049a910) and
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices
(0x1202c4210). One of the two will be used. Which one is undefined.
I found similar issue on stackoverflow
Class PLBuildVersion is implemented in both frameworks
I didn't pay attention about it to some moments while I begin get randomly such crash
(about 1 crash on 15-20 using of UIImagePickerController):
I'm not sure but I think it depend on log message(i.e message above).
It's sdk bug and issue have opened on Apple Radar.
Here my code for invoking UIImagePickerController:
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = allowEditing;
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[vc presentViewController: self.imagePicker animated: YES completion: nil];
My main question is: How can I resolve this issue right now? (Seems like Apple didn't hurry up to resolve it).
I wouldn't like creating custom image picker (without 100% working guarantee)
Are somebody faced with such issue?
Thanks in advance.
I decided try open source alternative for UIImagePickerController.
I go through list in this post How to select Multiple images from UIImagePickerController and integrated this one CTAssetsPickerController.
Log message still appear, but I'm testing it, there are no any issues for now.
I'd like to include a button in my Mac app which, when pressed, will launch the user's default calendar app. Preferably, I'd like to have the calendar open to a certain date.
This is for OS X Mountain Lion.
Is there a general way to do this?
Edit:
FWIW, this is what I'm doing now:
- (IBAction)launchCalendarApp:(id)sender
{
[[NSWorkspace sharedWorkspace] launchApplication:#"/Applications/Calendar.app"];
}
I know hardcoding the path like this is a bad idea which is why I'm asking the question.
Update:
This is what I ended up doing:
- (IBAction)launchCalendarApp:(id)sender
{
NSWorkspace *sharedWorkspace = [NSWorkspace sharedWorkspace];
NSString *iCalPath = [sharedWorkspace absolutePathForAppBundleWithIdentifier:#"com.apple.iCal"];
BOOL didLaunch = [sharedWorkspace launchApplication:iCalPath];
if (didLaunch == NO) {
NSString *message = NSLocalizedString(#"The Calendar application could not be found.", #"Alert box message when we fail to launch the Calendar application");
NSAlert *alert = [NSAlert alertWithMessageText:message defaultButton:nil alternateButton:nil otherButton:nil informativeTextWithFormat:#""];
[alert setAlertStyle:NSCriticalAlertStyle];
[alert runModal];
}
}
It sounds like all of the possible ways of doing this are workarounds until a better API is developed. My solution is similar to Jay's suggestion. I'm using the bundle identifier to get the path because I think it is a little less brittle. Apple is unlikely to change the bundle ID in the future even if they (or the user) decides to rename the app. Unfortunately, this method doesn't get me to a specific date. I will investigate further some of the other suggestions (using ical:// etc.) when I have more time.
Update 2:
NSGod has a terrific answer below that also opens the Calendar to a specific date provided your app is not sandboxed.
Note: I was still researching this while you updated with what you used, but I'll add this FWIW.
Using the bundle identifier of the application is generally a more robust way to refer to an app then using the name alone, as a user could move or rename the app in OS X, but they can't easily change the bundle identifier. Moreover, even while Apple renamed iCal.app to Calendar.app, the CFBundleIdentifier is still com.apple.iCal.
if (![[NSWorkspace sharedWorkspace]
launchAppWithBundleIdentifier:#"com.apple.iCal"
options:NSWorkspaceLaunchDefault
additionalEventParamDescriptor:nil
launchIdentifier:NULL]) {
NSLog(#"launching Calendar.app failed!");
}
The above code will work even if your app is sandboxed. You could potentially try to create a custom NSAppleEventDescriptor that would specify the equivalent of something like the following AppleScript code, but it will likely be denied because of the sandbox:
view calendar at date "Sunday, April 8, 2012 4:28:43 PM"
If your app doesn't have to be sandboxed, it's much easier if you use the Scripting Bridge, and with that method it's possible to select a specific NSDate.
Sample project using ScriptingBridge: OpenCalendar.zip
In that project, I use the following code:
SBCalendarApplication *calendarApp = [SBApplication
applicationWithBundleIdentifier:#"com.apple.iCal"];
[calendarApp viewCalendarAt:[self.datePicker dateValue]];
That will launch Calendar.app/iCal.app and change the calendar to the specified date.
So it sounds like for now you'd either have to resort to a hard wired approach, e.g.
// Launches Calendar.app on 10.7+
[[NSWorkspace sharedWorkspace] launchApplication:#"Calendar"];
Or use the URL scheme using what's supported by Calendar/iCal on OS X (pointed out by NSGod in comments below) similar to URL Scheme for opening the iCal app at a date or event?
:
// Launches iCal (works at least with 10.6+)
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:#"ical://"]];
You might try using EventKit to create a EKCalendarItem instance of the desired date and time, open the event, then remove it immediately thereafter. If it's well-timed, it may not even visibly blink on/off the user's calendar.
It's another kludge, but until NSWorkspace has an -openDate: method, kludges are the only recourse.
As discussed on this thread, it seems there's no url scheme to launch iCal
URL Scheme for opening the iCal app at a date or event?
I followed the login and share tutorial on developers.facebook.com and when posting on wall the app icon does not appear on post. it only shows labels and user input text. how do I make that app icon to show? does it have to be uploaded or is it something that I configure? before posting any answers or recomendations I already uploaded a photo to the developers.facebook dashboard. thank you in advance.. http://developers.facebook.com/docs/howtos/publish-to-feed-ios-sdk/ :
self.postParams =
[[NSMutableDictionary alloc] initWithObjectsAndKeys:
#"https://developers.facebook.com/ios", #"link",
#"https://developers.facebook.com/attachment/iossdk_logo.png", #"picture",
#"Facebook SDK for iOS", #"name",
#"Build great social apps and get more installs.", #"caption",
#"The Facebook SDK for iOS makes it easier and faster to develop Facebook integrated iOS apps.", #"description",
nil];
for anyone who had the same problem.. just upload the icon into a photo sharing site like photo bucket and assign that link to the code..
My end goal is to determine the most-recently-used web browser. I.e., a user may have both Safari and Firefox running, but which were they using most recently?
And so, I'm trying to enumerate the open apps, ordered by their window / visibility.
Does Cocoa / Applescript offer a way to retrieve this information?
You can use NSWorkspace's runningApplications method and NSRunningApplication's launchDate property to get you close to what you need.
Check out what the output if this code bit looks like in your console:
NSArray * arrayOfRunningApps = [[NSWorkspace sharedWorkspace] runningApplications];
if(arrayOfRunningApps)
{
for(NSRunningApplication * aUserApp in arrayOfRunningApps)
{
NSLog( #"%# launch time is %#", [aUserApp localizedName], [aUserApp.launchDate description] );
}
}
As for sorting on some criteria, that's really up to your implementation to do.
A couple caveats: these api's were introduced as of Snow Leopard (10.6) and
they only work on apps that the user can see (in the dock), not UNIX processes or admin/root daemons or whatever.
And I'm not certain about Applescript yet, but I'm hoping you'll be able to use this information to get to where you need to go.
I'm a Windows developer, but my team counterpart on the Mac side has asked me for help with an issue our Mac client has when the user wakes up his computer from hibernation.
I handle the wake up situation in our Windows client using the Windows WM_POWERBROADCAST message. This is a message that Windows sends to applications whenever there is a change in the power state of the hardware (on/off/suspend/resume).
Does OSX support a similar notification to tell running applications that the computer is suspending, resuming, or powering up or down?
TIA.
NSWorkspace has a bunch of notifications you can listen for.
Sorry, edited because the first post was completely wrong. NSWorkspace doesn't use the default notification center for notifications. This is copied mostly out of Apple's docs.
NSNotificationCenter *notCenter;
notCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
[notCenter addObserver:self
selector:#selector(didWake:)
name:NSWorkspaceDidWakeNotification
object:nil];