Trying to Write An Auto Answer App to Test iPhone - ios

I'm trying to write an app to auto answer an iphone when there are incoming calls.
The app can be launched by the user and run in the background.
I'm trying to use the IOS Private APIs to do this, but no success.
This is for testing purpose only and won't be submitted to the app store so using private APIs shouldn't be a problem. The phones aren't jailbroken though.
This is what I have in my AppDelegate.m file (didFinishLaunchingWithOptions):
id callCenterId = [TUCallCenter sharedInstance];
NSLog(#"callCenterId: %#", callCenterId);
TUCallCenter *object = [[TUCallCenter alloc] init];
NSLog(#"object: %#", object);
[object handleCallModelStateChanged: ^{
NSLog(#"this is an incoming call");
}];
When I run the app, I do see some outputs in the debug panel:
2016-02-01 10:32:38.849 AutoAnswer[312:63056] callCenterId: <TUCallCenter: 0x134642b40>
2016-02-01 10:32:38.851 AutoAnswer[312:63056] object: <TUCallCenter: 0x1346496c0>
But nothing is shown when I dial the phone when the app is in the foreground. I can't even get that to work, so forget about making it work in the background.
Any help would be appreciated.

Related

Alternative way of sending e-mail from app on iOS 10 when Mail app is deleted?

Now that Apple's "Mail" app can be deleted in iOS 10 and using [MFMailComposeViewController canSendMail] is always return NO when Mail app is deleted.
Is there any alternative way for sending Mail from inside the app?
You can use the MailCore Framework. This is an alternative to MFMailComposeViewController. Using this framework you can send an email programmatically. You have to construct each and every field i.e, To,CC,BCC,Subject,body etc. by yourself using this. One important thing to remember it has no UI.
CTCoreMessage *msg = [[CTCoreMessage alloc] init];
[CTSMTPConnection sendMessage:msg server:[server stringValue] username:[username stringValue]
password:[password stringValue] port:[port intValue] useTLS:tls useAuth:auth];
[msg release];

Objective-C HealthKit identify if source is from Apple iPhone or Apple Watch

I have an app where I am trying to integrate the HealthKit and pull steps related data aggregated by day using the HKStatisticsCollectionQuery. Requirement is to pull steps data specific to only iPhone and Apple Watch devices separately (no de-duplication) which have contributed to the health app.
The HKSource class only exposes the following properties:
name - Cannot be used as the user can change this to anything from just 'XXXX iPhone'
bundleIdentifier - Provides us the UUID for the device (unique per device, so different for every iPhone/Watch), and it looks like com.apple.health.UUID, here's what the Apple documentation says : "For apps, this property holds the app’s bundle identifier. For supported Bluetooth LE devices, this property holds a UUID for the device."
I am able to pull all sources (using a HKSourceQuery) which have the bundleIdentifier prefix of 'com.apple.health', but am unable to deduce which is an Apple iPhone versus which is an Apple iWatch.
Has anybody faced a similar situation before, and is there any other way to identify which source is an iPhone or Apple Watch?
Any help would be great!.Thanks!
Not the best solution but, I have figured out a way to distinguish between the watch and the phone using the following process:
I noticed that all step data coming from the iPhone/Watch have the following bundleIdentifier format:
com.apple.health.DeviceUUID
Note that manually entered data into the Health app has a bundle identifier of com.apple.Health (with a capital 'H').
So, first thing, get the device name for the phone using:
NSString *deviceName = [[UIDevice currentDevice] name];
Next, fetch all the sources for which there is a prefix match of 'com.apple.health' in the bundleIdentifier. This should give you the iPhone and the Apple watch as the valid sources and ignore the manual entries and all other apps.
Next, check if the name of the device is the same in the source, then its your iPhone, the other source should be your Apple Watch.
Here's a sample source query for fetching the sources :
- (void)fetchSources
{
NSString *deviceName = [[UIDevice currentDevice] name];
NSMutableArray *dataSources = [[NSMutableArray alloc] init];
HKQuantityType *stepsCount = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
HKSourceQuery *sourceQuery = [[HKSourceQuery alloc] initWithSampleType:stepsCount
samplePredicate:nil
completionHandler:^(HKSourceQuery *query, NSSet *sources, NSError *error)
{
for (HKSource *source in sources)
{
if ([source.bundleIdentifier hasPrefix:sourceIdentifier])
{
if ([source.name isEqualToString:deviceName])
// Iphone
else
// Apple Watch
[dataSources addObject:source];
}
}
}];
[self.healthStore executeQuery:sourceQuery];
}
You can now create a predicate with each source for your data pull using the NSPredicate class:
NSPredicate *sourcesPredicate = [HKQuery predicateForObjectsFromSource:source];
Note that my first thought was to match the UUID, but when I generate a UUID using the NSUUID class, it does not match with the one present in the bundle identifier in the pulled sources.
Also, you can change the name of the phone to whatever you want, it will automatically update in the Health app as well.
As I said, not the best solution but works for me, and it's the only way I could find to do this. Please let me know if you were able to find a better solution. Thanks.

orphaned UILocalNotification - confirmed

I have an app I am working on with allows the user to set and remove UILocalNotifications. In the course of developing this I have added and removed UILocalNotifications for testing and it seems to be working.
However I am seeing strange behavior where, after deleting my app from the device and running it again without setting any notifications, I will get a UILocalNotification. This notification was not set in this fresh install (checked through adding a breakpoint in my notification setup method).
Is it possible that I have an orphaned UILocalNotification from a previous install (yes, it seems highly unlikely to me too).
I've tried debugging this by setting the notification alertBody to something specific to each new install but this unique string doesn't get displayed in the alert. For example:
notif.alertBody = [NSString stringWithFormat:#"Alert for: %#", alertName];
Has anyone seen this sort of behavior before?
Update: Just confirmed orphaned UILocalNotifications: deleted the app from the device and ran the code below in my rootViewController on viewDidAppear. I get the following output in the Console:
2013-03-14 14:20:07.439 TestApp[16606:907] found alert: uigffhy
2013-03-14 14:20:07.444 TestApp[16606:907] found alert: uigffhy
Where this user was from some previous install. Ugh.
NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
for (UILocalNotification *notif in notificationArray) {
NSDictionary * info = notif.userInfo;
NSString * name = [info objectForKey:#"sequenceName"];
NSLog(#"found alert: %#", name);
}
Just detect if it's a fresh install (using NSUserDefaults) and do the following in applicationDidFinishLaunching:
[[UIApplication sharedApplication] cancelAllLocalNotifications];

How do I read Bluetooth headset name?

I want to read the bluetooth headset name.
I managed to rout the sound trough the headset and to get the current route for the kAudioSessionProperty_AudioRoute.
I was not able to find any documentation how to read the headset name. Any link, advice or code is welcome.
You can't read the name of the device as it is written in Settings/Bluetooth.
However, you can access to the name written in the device (which sometimes is different, I've seen this case) :
EASessionController = [EADSessionController sharedController];
_accessoryList = [[NSMutableArray alloc] initWithArray:[[EAAccessoryManager sharedAccessoryManager] connectedAccessories]];
for (EAAccessory *key in _accessoryList)
{
NSLog(#"Name : %#", key.name);
}
More information at EAAccessory class.

NSFileCoordinator error when using UIManagedDocument in iOS 5.0 simulator

I am using a UIManagedDocument in iOS 5.0, running the app on the simulator, using XCode 4.2 under OSX 10.6. The code in question looks as follows:
if (![[NSFileManager defaultManager] fileExistsAtPath:[self.photoDatabase.fileURL path]]) {
// does not exist on disk, so create it
[self.photoDatabase saveToURL:self.photoDatabase.fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
[self setupFetchedResultsController];
[self fetchFlickrDataIntoDocument:self.photoDatabase];
}];
} else if (self.photoDatabase.documentState == UIDocumentStateClosed) {
// exists on disk, but we need to open it
// *** the following line generates the message ***
[self.photoDatabase openWithCompletionHandler:^(BOOL success) {
//[self setupFetchedResultsController];
}];
} else if (self.photoDatabase.documentState == UIDocumentStateNormal) {
// already open and ready to use
[self setupFetchedResultsController];
}
Running the marked line creates the following message on the log:
2012-01-10 22:33:17.109 Photomania[5149:4803] NSFileCoordinator: A surprising server error was signaled. Details: Connection invalid
After the message is sent, the UIManagedDocument may or may not work—I have not found the circumstances that determine this, yet.
I am pretty sure that the code is correct, as it's actually one of the code examples in the CS193p course from Stanford. The whole example can be downloaded at their website under
http://www.stanford.edu/class/cs193p/cgi-bin/drupal/
Direct link to the code:
http://www.stanford.edu/class/cs193p/cgi-bin/drupal/system/files/sample_code/Photomania_0.zip
Additionally, the code runs fine on the device itself, without generating the "surprising" message, and running all the code that comes afterwards just fine.
I have not found anything on Google, neither on the Apple Developer pages. Restarting the simulator, or XCode, or reinstalling both of them does not change the behaviour.
Any ideas?
I can only say that I've had this happen to me several times. For me, I'm lazy after I update my dataModel and so far, each time I've gotten this error it was because I had changed my data model. Usually, all I need to do is delete my app from the simulator and re-run it and it has always turned out fine. Hope this helps someone out there.
I think I have found the answer. It looks like the automatic saving for UIManagedDocument kicks in only after a few seconds on the simulator.
So I minimized the app on the simulator, by pressing the home button, and then clicked on the icon to maximize it again. And then I terminated the app in simulator.
When I re-launched the app, the database was loaded. The error still shows up - it comes because the document is in "closed" state (that's normal - that's why CS193P asked to call openWithCompletionHandler), but my data across launches is preserved. Unfortunately I have to do the minimize/maximize routine before terminating the app, or the changes are discarded at next launch.
Can you verify that this is the behavior you are able to recreate? At least for testing purposes this should be a good enough trick to use.
Try upgrading to the latest iOS 5.1. I don't think UIManagedDocument with iCloud works reliably in 5.0. This has been my experience.
I love the Stanford iTunes class. However, I think the sample code for using UIManagedDocument is wrong. In fact, he notes in the demo that he is only doing it that way because he wants to just fetch the information right then. In the code comments, he says not to use the auto-save features because the data will not be saved if the app quits. however, UIManagedDocument will save anything that's necessary before quitting. It has all pertinent handlers for quitting/multitasking/etc to make sure the data is saved.
So, if you are using that code as your example, here's a version that should work, and does not use saveToURL (I don't have a flickr account, so I didn't actually run it - but this is how the class is designed to work). Please let me know if it does not work.
- (void)fetchFlickrDataIntoDocument:(UIManagedDocument *)document
{
NSManagedObjectContext *ctx = [[NSManagedObjectContext alloc] initWithConcurrencyType: NSPrivateQueueConcurrencyType];
ctx.parentContext = document.managedObjectContext;
[ctx performBlock:^{
NSArray *photos = [FlickrFetcher recentGeoreferencedPhotos];
for (NSDictionary *flickrInfo in photos) {
[Photo photoWithFlickrInfo:flickrInfo inManagedObjectContext:ctx];
// Push changes to document MOC
[ctx save:0]; // propagates changes to parent MOC
// and tell the document it is dirty and needs to be saved
// It will be saved when the document decides its time to save
// but it *will* be saved.
[document updateChangeCount:UIDocumentChangeDone]
}
}];
}
Still had errors when the last path component for document file url was #"Database". Adding an extension #"Database.db" seems to have fixed it, everything running fine now. Have also upgraded to Lion though.
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
url = [url URLByAppendingPathComponent:#"Database.db"];

Resources