In my application I want to switch on/off iPhone Bluetooth.i m using sdk 4.3..I got some idea regarding Bluetooth manager framework, but it's not working in 4.3..any ideas? or can we programmatically determine whether Bluetooth is ON/OFF?
Please note that you wouldn't be able to publish the app on the App Store because doing that must use private API.
If you still want to do that you should read this link:
Is there a way to toggle bluetooth and/or wifi on and off programmatically in iOS?
Pay attention for adding GameKit framework for it to work and not using all the other thing written like adding .h files etc. unless gameKit doesn't sole all the problems.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
#if TARGET_IPHONE_SIMULATOR
exit( EXIT_SUCCESS ) ;
#else
/* this works in iOS 4.2.3 */
Class BluetoothManager = objc_getClass( "BluetoothManager" ) ;
id btCont = [BluetoothManager sharedInstance] ;
[self performSelector:#selector(toggle:) withObject:btCont afterDelay:1.0f] ;
#endif
return YES ;
}
#if TARGET_IPHONE_SIMULATOR
#else
- (void)toggle:(id)btCont
{
BOOL currentState = [btCont enabled] ;
[btCont setEnabled:!currentState] ;
[btCont setPowered:!currentState] ;
}
#endif
the above lines of code i got from here
Related
in iOS 4.x, there were APIs about my requirement, But it seems changed into private in 5.x, And It seems to removed in 6.x. (Actually it seems can't be called in sandbox)
Getting SSID list for 802.11 is very essential idea for our new project.
This code work well in order to get SSID.
#import <SystemConfiguration/CaptiveNetwork.h>
#implementation IODAppDelegate
#synthesize window = _window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
CFArrayRef myArray = CNCopySupportedInterfaces();
CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
NSLog(#"Connected at:%#",myDict);
NSDictionary *myDictionary = (__bridge_transfer NSDictionary*)myDict;
NSString * BSSID = [myDictionary objectForKey:#"BSSID"];
NSLog(#"bssid is %#",BSSID);
// Override point for customization after application launch.
return YES;
}
And this is the results :
Connected at:{
BSSID = 0;
SSID = "Eqra'aOrange";
SSIDDATA = <45717261 27614f72 616e6765>;
}
I believe that there is no solution for this. the reason is:
Even user disabled location service, an App which accesses SSID list(actually BSSID) can infer location of user by using skyhook or something similar solution.
This information is not confirmed by Apple, But I'm pretty sure about it.
I need to write a background application in iOS which listens to incoming phone calls on the iPhone.
Is it possible? Can anyone suggest some good pointers ?
Thankyou
This would be very much against Apple's privacy policy and there's no chance an app like this would be approved.
There are call recording apps that sneak around this restriction, though, but they use third party services and no actual built-in iPhone API's.
You can do it in applicationWillEnterForeground using CTCallCenter's CTCallState properties. Don't forget to import the CoreTelephony framework. Here's an example:
#import <CoreTelephony/CTCall.h>
#import <CoreTelephony/CTCallCenter.h>
#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[callCenter setCallEventHandler:^(CTCall *call) {
if ([[call callState] isEqual:CTCallStateIncoming] || [[call callState] isEqual:CTCallStateDialing]) {
if ([viewController isPlaying])
{
NSLog(#"Call was started.");
}
} else if ([[call callState] isEqual:CTCallStateDisconnected]) {
if (callWasStarted)
{
NSLog(#"Call was ended.");
}
}
}];
}
I want to check whether the device is iPhone or iPad using the macro.
I have a file Constant.h where I have given values using #define.
Now, I want to check device using #ifdef #endif.
Follwing method can be possible only in the .m file.
But I have only one .h only.
- (BOOL) isPad{
#ifdef UI_USER_INTERFACE_IDIOM
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
#else
return NO;
#endif
}
So above method is not useful for me ?
Is there any way to do this ? Or any other way?
I have simple answer to this question.
#define isiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? YES : NO)
This will returns 1 if device is iPad and 0 if device is iPod or iPhone.
You can't check it by macro, because macro is expanded during compilation. So you need to know device type at compile time.
If you want to support both devices at runtime, you need to check device type and use appropriate set of constants.
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 30200
UIDevice* thisDevice = [UIDevice currentDevice];
if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
// etc.
}
#endif
i want to know the user uses the iphone or ipad,if the user uses the iphone i want to open the camera,if he uses the ipad or runs in simulator i want to open the library. how it is possible?
how to find the details of devices?
how to know current using device by user through xcode?
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType isEqualToString:#"iPhone"])
{
//your code
}
.....
Hope this helps.
EDIT:
See this thread -determine-device-iphone-ipod-touch-with-iphone-sdk .
[[UIDevice currentDevice].model hasPrefix:#"iPhone"]
Use the "hasPrefix" so that it works in simulator.
You should not determine whether there is a camera by looking at the model. This is not future proof - for instance, you would not be supporting the iPad 2's camera.
UIImagePickerController has a special method to determine whether a camera in available:
+ (BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType
With sourceType being one of
UIImagePickerControllerSourceTypePhotoLibrary,
UIImagePickerControllerSourceTypeCamera,
UIImagePickerControllerSourceTypeSavedPhotosAlbum
Make use of this to identify devices.
// If iPhoneOS is 3.2 or greater then __IPHONE_3_2 will be defined
#ifndef __IPHONE_3_2
typedef enum {
UIUserInterfaceIdiomPhone, // iPhone and iPod touch
UIUserInterfaceIdiomPad, // iPad
} UIUserInterfaceIdiom;
#define UI_USER_INTERFACE_IDIOM() UIUserInterfaceIdiomPhone
#endif // ifndef __IPHONE_3_2
but if you want to check if camera is available I think you can make use of UIImagePickerController's static method
+ (BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType
Working on Vaibhav Tekam's answer, I used this
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType hasPrefix:#"iPhone"])
{
//your code
}
or
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType hasPrefix:#"iPad"])
{
//your code
}
etc.
It's much easier that way as it covers all models.
I am building an app that takes advantage of 4.0 features like in-app messaging but I also want my app to work on all 3.x versions. How do I check if the device can use MFMessageComposeViewController?
Apple advises to use the NSClassFromString function to determine if the class is available. Don't forgot to weak link against the message framework as mentioned before.
Example from the MessageComposer sample:
-(IBAction)showSMSPicker:(id)sender {
// The MFMessageComposeViewController class is only available in iPhone OS 4.0 or later.
// So, we must verify the existence of the above class and log an error message for devices
// running earlier versions of the iPhone OS. Set feedbackMsg if device doesn't support
// MFMessageComposeViewController API.
Class messageClass = (NSClassFromString(#"MFMessageComposeViewController"));
if (messageClass != nil) {
// Check whether the current device is configured for sending SMS messages
if ([messageClass canSendText]) {
[self displaySMSComposerSheet];
}
else {
feedbackMsg.hidden = NO;
feedbackMsg.text = #"Device not configured to send SMS.";
}
}
else {
feedbackMsg.hidden = NO;
feedbackMsg.text = #"Device not configured to send SMS.";
}
}
Link: MessageComposer sample
Update: The sample code I posted checks for the availability of the SMS composer, checking for the mail composer is similar.
Try this:
#import <MessageUI/MessageUI.h>
#include <dlfcn.h>
if ( dlsym(RTLD_DEFAULT, "MFMailComposeErrorDomain") != NULL ) {
// MFMessageComposeViewController framework is available
} else {
// do alternative for no MFMessageComposeViewController
}
Don't forget to weak link the MFMessageUI framework.
You could check the device's current operating system using the UIDevice class.
http://developer.apple.com/iphone/library/documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html
The systemName and systemVersion properties may be what you're looking for. You'll also need to weak link the framework!