How to detect an arrived sms message in IPhone? - iphone

How to detect an arrived SMS in code? and how can I auto check if it contains specific strings? for example I wanna send SMS to the Iphone which contains "specifString" and I want the receiver Iphone auto open my app.

You cannot, get a notification when a person receives a SMS, but you can enter a special url in that SMS that then would launch your application when clicked.
In your Info.plist you have to define some key-value pairs:
And then your app is launched when url like this is clicked:
yourapp://?foo=1&bar=2
as you can see, you can pass parameters to your app.
In your app you get a special event, when your app is launched from an url.
4.1 and earlier:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
// Do something with the url here
}
**4.2 and later **
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
// Do something with the url here
}
More details in documentation: "Implementing Custom URL Schemes"
Edit after WWDC Keynote 06.06.2011
New API iMessaging now supports messaging on iPad and also receipts to know if your message has been delivered.

You can not achieve what you are trying to do. Apple restricts this kind of things, because this amounts to spying on the user who uses your application.

Related

Custom URL Scheme for iOS App when not backgrounding

I have set up a custom deep-linking iOS URL scheme for my app, and I listen for it in
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
I parse the URL and send a notification using NSNotificationCenter, with the URL as the object, to the appropriate class to handle the URL.
This all works great when the app is "backgrounded" but when the app is fully closed out of multitasking, it seems like the notification never gets sent (or received). Am I missing something about the process of notifications when the app isn't in backgrounding? Is there another way to pass along the information from the URL? Or is there at least a way to tell if the app is coming out of backgrounding or if it is a fresh launch?
Thanks!
You should check the launchOptions dictionary that is passed into applicationDidFinishLuanching:withOptions:.
For full details on what is included in the options dictionary: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html

Launching App from another App using NSURL

There are apps in the iOS app store that let you send encrypted messages via sms and it seems like they are using NSURL to create a clickable link that opens their app automatically (from the iMessage app) with the "hidden message" already showing in the app.
My question is, how does one store information within an NSURL? I figured out who to launch my app from another app using NSURL but how can you store extra information for the launched app to use such as text, an image, or a link to an online video?
I apologize if this is a basic question, I haven't had to work with URLs much. Many thanks.
We can achieve communication between apps through the URL Schemes concept.
if you can go through this link below, you will get some idea on how to share data between the applications
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-working-with-url-schemes/
When you register an URL scheme in your application's info.plist like myapp you can use the following url's to invoke your application.
myapp://
myapp://some/path/here
myapp://?foo=1&bar=2
myapp://some/path/here?foo=1&bar=2
And you can check the received url's in the
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
method of app delegate and do the action according to each url.
Reference : Launching application via custom url scheme
The data is not stored in NSURL. However, you can pass parameters along with the URL and accordingly retrieve them in the new opened app.
Now you can use these params in the way you want.

Flickr integration in iOS app

I have an issue while integrating flickr in iOS app.
When I click on authorize button then it shows alert message as safari cannot open webpage because the address is invalid.
If anyone knows then please help me.
Thanks in advance.
My best guess is you are missing URL SCHEME in your project plist. Below is the screenshot showing current sample from flickr sdk which I downloaded from github and there is a setup done for URL Scheme handling.
Its called oAuth handling when SAFARI is finished verifying the credentials and want to return to the application it returns URL which can be handled by the application mentioned in plist and which we will handle from application delegate using following function
So you need to provide your URL identifier and URL Scheme for your project which you can get if you register in flickr api.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
}

Does opening an iphone app via URL still call applicationDidFinishLaunchingWithOptions

If you open up an iphone app from a custom url scheme, does the applicationDidFinishLaunchingWithOptions method still get called?
In my app I create a UITabBarController with 4 UIViewControllers in my applicationDidFinishLaunchingWithOptions. If my app is closed and I open it from the custom url, do I also need to create the UITabBarViewController and UIViewControllers in the openURL:sourceApplication:annotation method?
The discussion in the documentation for
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
states that
If an application is launched as a result of another application
requesting it to open a URL resource, UIApplication first sends the
application a application:didFinishLaunchingWithOptions: message and
then it invokes this method. This method supplies the delegate of the
handling application with the bundle ID of the source application as
well as any annotation information from that application. If an
application is already running when it receives a request to open a
URL, this method is called but
application:didFinishLaunchingWithOptions: isn’t.

Launching application from a SMS message

I am new to iphone application development.
I have a sample application that needs to be launched from a SMS message. I have no idea on how to do this. Please help me.
Note that if SMS operates in the same manner as Mail on the iPhone, you'll need to enclose your custom URL in brackets to make it launch the application responding to that scheme. For example,
<yourapp://yoururl>
will work, but
yourapp://yoururl
will not.
Allow your application to respond to some url (eg: myapp://launch ) and include the url in the SMS, when the user launches that URL your application will launch.
I'm sure that is not the most straight forward way (since the SMS needs to include your custom URL) but I don't know if it is possible with any arbitrary SMS to launch an arbitrary applciation
do a google on iphone URL scheme and you will find lots of detail on how to implement this
here is an example
the below appdelegate method tells the full url that used to open your app
-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
//you could parse the url and take action according to that
}
The below app delegate method tells which app caused to open your app
- (BOOL)application:(UIApplication *)application openURL: (NSURL *)url sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
//you could capture the refered app custom url and open back from your app
return YES;
}
with following code snippet you could open the app that opened your app
NSURL *urlObj = [NSURL URLWithString:url];
[[UIApplication sharedApplication] openURL:urlObj];
Pass the custom app url.
It works fine. thanks hhafez!
I composed a SMS with url format "myapp://". It didn't work. Then I tried "", then it worked. thanks Brad!