Enable/Disable Wifi on Jailbroken Device in iOS7 - ios7

I am looking for a specific set of function calls into the iOS7 private frameworks / dylibs etc to enable/disable WiFi programmatically on a device running iOS7, or alternatively some other workaround to do the same. If you are tempted to mark this question as a duplicate, please reference a question (an answer would also be nice!) that refers to iOS7. This would have to be a question asked after September, 2013, when iOS7 was released. The private framework class that did this in iOS6, SBWiFiManager, no longer exist in iOS7. I've read through many StackOverflow questions and answers, and grep'd through a lot of framework header files already, so I am aware of some of the ways to go about figuring this out.
* EDIT *
It turns out this is still the correct answer, also has reference to the necessary framework:
How can I enable and disable WiFi connectivity with a jailbroken iOS device?

Related

Watch Kit: is it possible to vibrate watch programmatically?

Is it possible to vibrate watch while Watch Extension is running? We can do it on iOS in this way (force iPhone to vibrate):
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
I hope there is something similar on WatchKit.
Update: I have added issue to Apple radar and recieved the answer:
Engineering has determined that your bug report (20019274) is a duplicate of another issue (19025053) and will be closed.
19025053 is still open.
Update 2: AudioServicesPlayAlertSound() not working on watch simulator with any sound ID. Seems like function is not supported.
You can now ask the Watch to vibrate if you target watchOS 2.0
To do this all you need to do is call playHaptic on a WKInterfaceDevice instance with any WKHapticType. In the example below it will play the notification haptic.
Swift 3
WKInterfaceDevice.current().play(.notification)
Objective-C
[[WKInterfaceDevice currentDevice] playHaptic:WKHapticTypeNotification];
You can further read the
Apple WKInterfaceDevice Documentation
That's a great question, but unfortunately the answer is no. WatchKit doesn't have any APIs available to control haptic feedback. If you would really like to see this feature supported, I'd suggest you file a radar as a feature request.
This is the answer in objective-c after watchOS 2
[[WKInterfaceDevice currentDevice] playHaptic:WKHapticTypeNotification];
With WatchKit, you have to remember that your code runs on the iPhone and not on the watch. Therefore, AudioServicesPlaySystemSound call from a WatchKit extension would run on the iPhone, not on the watch. It will make the iPhone vibrate.

In OS X 10.9 (xcode 5.1), how to show local notification on top-right(menu bar) in my program?

Why local notification is no supported by OS X 10.9? I know IOS has UILocalNotification Class.
I want to show some notification bellow menu bar which is generated by my program.
Is there any alternate way to do this? Or should I write my own local notification view?
It sounds like you are looking for NSUserNotification functionality, which goes along with the MacOS NSUserNotificationCenter.
I've linked the documentation at Apple to help you out.
As you are learning, many classes and objects supplied in the iOS SDK don't have exact same classes and objects in the MacOS SDK. Anything with "UI" in the framework name is usually meant only for iOS.

Receive remote control events without audio

Here is some background information, otherwise skip ahead to the question in bold. I am building an app and I would like it to have access to the remote control/lock screen events. The tricky part is that this app does not play audio itself, it controls the audio of another device nearby. The communication between devices is not a problem when the app is in the foreground. As I just found out, an app does not assume control of the remote controls until it has played audio with a playback audio session, and was the last do so. This presents a problem because like I said, the app controls ANOTHER device's audio and has no need to play its own.
My first inclination is to have the app play a silent clip every time it is opened in order to assume control of the remote controls. The fact that I have to do this makes me wonder if I am even going to be allowed to do it by Apple or if there is another way to achieve this without fooling the system with fake audio clips.
QUESTION(S): Will Apple approve an app that plays a silent audio clip in order to assume control of the remote/lock screen controls for the purpose of controlling another device's audio? Is there any way of assuming control of the remote controls without an audio session?
P.S. I would prefer to have this functionality on iOS 4.0 and up.
P.P.S I have seen this similar question and it has gotten me brainstorming but the answer provided is not specific to what I need to know.
NOTE: As of iOS 7.1, you should be using MPRemoteCommandCenter instead of the answer below.
You create various system-provided subclasses of MPRemoteCommand and assign them to properties of the [MPRemoteCommandCenter sharedCommandCenter].
I'm keeping the rest of this around for historical reference, but the following is not guaranteed to work on recent iOS versions. In fact, it just might not.
You definitely do need an audio player but not necessarily an explicit session to take control of the remote control events. (AVAudioSession is implicit to any app that plays audio.) I spent a decent amount of time playing with this to confirm this.
I've seen a lot of confusion on the internet about where to set up the removeControlEventRecievedWithEvent: method and various approaches to the responder chain. I know this method works on iOS 6 and iOS 7. Other methods have not. Don't waste your time handling remote control events in the app delegate (where they used to work) or in a view controller which may go away during the lifecycle of your app.
I made a demo project to show how to do this.
Here's a quick rundown of what has to happen:
You need to create a subclass of UIApplication. When the documentation says UIResponder, it means UIApplication, since your application class is a subclass of UIResponder. In this subclass, you're going to implement the remoteControlReceivedWithEvent: and canBecomeFirstResponder methods. You want to return YES from canBecomeFirstResponder. In the remote control method, you'll probably want to notify your audio player that something's changed.
You need to tell iOS to use your custom class to run the app, instead of the default UIApplication. To do so, open main.m and change this:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([RCAppDel`egate class]));
to look like this:
return UIApplicationMain(argc, argv, NSStringFromClass([RCApplication class]), NSStringFromClass([RCAppDelegate class]));
In my case RCApplication is the name of my custom class. Use the name of your subclass instead. Don't forget to #import the appropriate header.
OPTIONAL: You should configure an audio session. It's not required, but if you don't, audio won't play if the phone is muted. I do this in the demo app's delegate, but do so where appropriate.
Play something. Until you do, the remote controls will ignore your app. I just took an AVPlayer and gave it the URL of a streaming site that I expect to be up. If you find that it fails, put your own URL in there and play with it to your heart's content.
This example has a little bit more code in there to log out remote events, but it's not all that complicated. I just define and pass around some string constants.
I bet that a silent looping MP3 file would help work towards your goal.
Moshe's solution worked great for me! However one issue I noticed is when you paused the audio, the media controls would go away and you won't be able to play it again without going back into the app. If you set the Media Info on the lock screen when you play the audio then this won't happen:
NSDictionary *mediaInfo = #{MPMediaItemPropertyTitle: #"My Title",
MPMediaItemPropertyAlbumTitle: #"My Album Name",
MPMediaItemPropertyPlaybackDuration: [NSNumber numberWithFloat:0.30f]};
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:mediaInfo];

Reasons for MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification

The documentation for MFMessageComposeViewController says you should check [MFMessageComposeViewController canSendText] before trying to create a MFMessageComposeViewController.
It also says:
in iOS 5.0 or later, you should register as an observer of the MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification notification to be notified of changes in the availability of sending text messages.
What possible reasons could there be for the availability of text messaging changing?
Is it just to make Linus Torvalds cry?
Background: I’m creating an iOS app that requires the ability to send SMS messages. I’ve added sms to UIRequiredDeviceCapabilities in Info.plist. It should only run on iPhones (according to Apple docs, I read somewhere this does not include iPod touches or iPads solely with iMessage)
If text messaging is not available, the app is useless, and should present some useful error message.
Update: I’ve tested with my iPhone 4S that simply having a locked SIM still returns YES from canSendText – still not a reason for message sending ability to change.
Update #2: I have created a simple test app to see what might cause it. I have not received the notification at all.
Things that don’t cause MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification
Turning iMessage on & off
Losing WiFi connectivity
Turning on airplane mode
Locking iPhone SIM card
Things that can cause canSendText to change between YES/NO (but not send a notification)
Turning iMessage on & off on an iPad (I assume iPod touch too)
I’m guessing the correct case is for iPads and iPod touches when iMessage is turned on or off, however, there must be a bug (either in my test code or Apple’s) that’s preventing this from working.
If you need this notification, I tried just checking [MFMessageComposeViewController canSendText] again on UIApplicationDidBecomeActiveNotification. This sometimes works, but if you switch quickly between Settings.app and your app, it may not have changed yet by the time you switch to your app, causing canSendText to still reflect the old value.
My solution for now is just going to be simply checking canSendText just before relevant decisions are made, and handle the (rare?) case where it may have changed without me knowing in some appropriate way.
Since MFMessageComposeViewController can use iMessage in iOS5, I'm guessing it's probably to handle the case where iPod Touches and Wi-fi iPads lose internet connectivity while a message is being typed.
I managed to rule out another scenario where it does not trigger MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification.
Sender iPad with a working wifi connection
Reciepient Android phone
Result: MessageComposeResult == MessageComposeResultSent, MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification was not triggered
Next I tried the same scenario with iMessage in order to duplicate the final results. (== not being able to send an iMessage).
Then I realized that iMessage was able to tell me in advance this would never work by putting a red exclamation next to the recipients name with the message this person is not registered with iMessage. The MFMessageComposeViewController does not do this!!!
My current conclusion is: canSendText should be named canComposeText.
MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification does nothing.
Currently, there is no case where MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification is sent.
The only time when the value of canSendText changes is when iMessage is turned on/off on an iPad or iPod Touch (not an iPhone, which has SMS messaging).
Even when canSendText changes, no notification is sent.
(Unless it’s just a bug in my test code?) This appears to be a bug or missing feature in Apple’s code.

Override / cancel iPad application switch gesture

I want to track four finger touches in my application, but they are cancelled as the iPad uses the four finger swipe to switch applications.
Is there a way to cancel / override this gesture?
I looked into this for a game I worked on and I could not find a way to override it. Even if you found a way, it would probably get you rejected from the app store, since there doesn't seem to be any public API for it.
This be my answer. I'm not sure how you'd go about to actually execute the below as I guess implementions do things differently, but generally it sounds as there is a possibility, because after all these are the words of Apple regarding the multitasking gestures:
"Developers are encouraged to evaluate any existing interactions in
their applications for potential sources of interference. In order to
properly interoperate with multitasking gestures, applications must
properly handle the following methods and notifications:
touchesCancelled:withEvent: (UIResponder) cancelTrackingWithEvent:
(UIControl) applicationDidBecomeActive: and
applicationWillResignActive: (application delegate)
UIApplicationDidBecomeActiveNotification and
UIApplicationWillResignActiveNotification notifications These can be
enabled for development via Xcode so you can update your apps to
interoperate with these new gestures. Test them and give us your
feedback in the Apple Developer Forums."
I really don't think you can because I have watched countless videos on how to override on iPhone/iPod but there are no ones for iPad must be so you can't cheat on games!