Has anyone managed to get the iPad iOS 10 simulator to trigger a shake event? - ios-simulator

Broken suddenly in iOS 10 simulators.
Prepare with:
[[UIApplication sharedApplication] setApplicationSupportsShakeToEdit:YES];
Implement:
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
And the -motionBegan is never called.

Ok, so it turns out that they have changed how this works, and my "Prepare" above is now insufficient in iOS 10. You don't need to set that.
Now you must implement the motionBegan in the first responder that will receive the event, if it is your VC you need to implement:
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)viewDidAppear:(BOOL)animated {
[self becomeFirstResponder];
}

Related

WCSession error domain code 7005: Device is not Paired

By making use of WCSession sendMessage, I am getting ErrorDomainCode 7005 constantly within one of my Projects.
I get this error when testing with all simulators and also on real iPhone and paired Apple Watch. Devices are definitely paired.
The exact same code works fine for other (newer) projects that I created from scratch together with a Watch Extension.
I do have this problem only in an older Project where I have added a watch extension recently.
The watch app simply does not communicate with the iPhone app.
Following is my Code:
AppDelegate in didFinishLaunchingWithOptions:
if ([WCSession isSupported]) {
[[WCSession defaultSession] setDelegate:self];
[[WCSession defaultSession] activateSession];
}
AppDelegate: Receiver of Message
- (void)session:(WCSession *)session
didReceiveMessage:(NSDictionary<NSString *, id> *)message
replyHandler:(void (^)(NSDictionary<NSString *, id> *_Nonnull))replyHandler {
replyHandler(#{ #"message" : #"OK" });
}
Watch Extension InterfaceController: awakeWithContext
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
[[WCSession defaultSession] isReachable];
if ([WCSession isSupported]) {
[[WCSession defaultSession] setDelegate:self];
[[WCSession defaultSession] activateSession];
}
[self.wcSession sendMessage:applicationData
replyHandler:^(NSDictionary *reply) {
NSLog(#"OK");
}
errorHandler:^(NSError *error) {
//catch any errors here
[self.testLabel setText:[error.userInfo objectForKey:#"NSLocalizedDescription"]];
}
];
This is what I've tried up to now:
reset content and settings of all simulators
deleted watch app from watch &from iPhone
via settings in Watch App on Phone: Removed Watch Extension for Phone App and reinstalled it
Tried setting up the iPhone WCSession in AppDelegate INIT Method
I am struggling with this issue for many days now. So every hint is highly appreciated.

Push notifications are not working in iOS 9

I have upgraded my devices to iOS 9 and my Xcode environment to 7.0
beta. Push notifications are not working in iOS 9?
Here is my code:
float ver = [[[UIDevice currentDevice] systemVersion] floatValue];
if(ver >= 8 && ver<9)
{
if ([[UIApplication sharedApplication] respondsToSelector:#selector(registerUserNotificationSettings:)])
{
[[UIApplication sharedApplication] registerForRemoteNotifications];
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
}else if (ver >=9){
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else{
//iOS6 and iOS7 specific code
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert];
}
Push notifications are working fine on iOS 8 to 8.3 built with Xcode 6.4.
After adding the code in your project and creating the certificate and Ad-Hoc Profile -
*Just enable this from your X-code*
for more details - iOS 9 Push Notification Tutoriyal
I ran into the same problem. I solved it by creating an Ad-Hoc Profile. I noticed push is not happening when I use a development profile. And the other thing I noticed was the Device Token gets changed for every fresh install which is kind of weird as we have to update the server for every new instance.
You can go through this article for a better understanding :
iOS 9 Push Notifications
write this code in didFinishLaunchingWithOptions
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
and add this method to AppDelegate as i have used for parse push notification service
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
currentInstallation.channels = #[ #"global" ];
[currentInstallation saveInBackground];
}
Please try this code as its working for my IOS 9 application
Write a Code in AppDelegate DidFinishLaunchWithOption
if([[UIApplication sharedApplication] respondsToSelector:#selector(isRegisteredForRemoteNotifications)])
{
[[UIApplication sharedApplication] registerUserNotificationSettings: [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound)]; #endif
}
Make sure the following items are well checked for the Push notification on the server
PEM File generated with selecting the Cert & Private key from the originator
Apple service enabled and pointing to Sandbox/Live correctly
Push notification token is received in below function and not any Error is returned which is well send to the server (LAMP service) that is sending the APNS Push notification to device Token.
Check the Apple APNS response code in the server with the Push send to the token.
Enabled Push notification in the settings as if you do any goof up in the '|' symbol code you may see the sound, badge options not shown in Apple General Notification settings
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *devicetokenString = [[[[deviceToken description] stringByReplacingOccurrencesOfString: #"<" withString: #""] stringByReplacingOccurrencesOfString: #">" withString: #""] stringByReplacingOccurrencesOfString: #" " withString: #""];
DLog(#"Did Register for Remote Notifications with Device Token DATA (%#) \n STRING token (%#)", deviceToken,devicetokenString);
//If Same token received again dont take any action else save in NSUserdefaults or system and send to server to register against this device to send push notification on the token specified here.
}
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
DLog(#"Did Fail to Register for Remote Notifications");
DLog(#"%s:%#, %#",__PRETTY_FUNCTION__,error, error.localizedDescription);
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
DLog(#"Did Receive for Remote Notifications with UserInfo:%#", userInfo);
}
Hope this is well explained if any help do post your updated code so we can help you.
If you are using Diawi for install application than push notification not working in IOS 9..
You install application though Xcode..

Watchkit , openParentApplication with WatchKit Extension

First times doesn't work "Null"( before open App in iPhone )
and some times doesn't work but i want one loop or timer for repeat this request for get result :
here is my code
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply
{
// Temporary fix, I hope.
// --------------------
__block UIBackgroundTaskIdentifier bogusWorkaroundTask;
bogusWorkaroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[[UIApplication sharedApplication] endBackgroundTask:bogusWorkaroundTask];
}];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] endBackgroundTask:bogusWorkaroundTask];
});
// --------------------
__block UIBackgroundTaskIdentifier realBackgroundTask;
realBackgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
reply(nil);
[[UIApplication sharedApplication] endBackgroundTask:realBackgroundTask];
}];
// Kick off a network request, heavy processing work, etc.
// Return any data you need to, obviously.
// reply(nil);
reply(#{#"Confirmation" : #"Text was received."});
[[UIApplication sharedApplication] endBackgroundTask:realBackgroundTask];
// NSLog(#"User Info: %#", userInfo);
}
Watch App Code
- (void)willActivate {
// This method is called when watch view controller is about to be visible to user
[super willActivate];
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:#"MyCamande", #"OK", nil];
[InterfaceController openParentApplication:dictionary reply:^(NSDictionary *replyInfo, NSError *error) {
NSLog(#"Reply received by Watch app: %#", replyInfo);
}];
}
how can recall for get finally result
Well, I would not recommend you using anything, related to network operations on watch itself. First of all because Apple does not recommend to do it for obvious reasons. The only network thing that is performed on the watch directly is loading images.
I have been struggling with network operations and watch for like a week and came to a conclusion, that the most stable way to do it right now is not obvious.
The main issue is that WKInterfaceController.openParentApplication(...) does not work as expected. One can not just request to open iPhone app and give back the response as is. There are tons of solutions stating that creating backgound thread in - (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply would work just fine, but it actually does not. The problem is that this method has to send reply(...); right away. Even creating synchronious requests won't help, you will keep receiving "error -2 iPhone application did not reply.." like 5 times our of 10.
So, my solution is following:
You implement:
func requestUserToken() {
WKInterfaceController.openParentApplication(["request" : "token"], reply: responseParser)
}
and parse response for error that might occur if there's no response from iPhone.
On iOS side
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply
{
__block UIBackgroundTaskIdentifier watchKitHandler;
watchKitHandler = [[UIApplication sharedApplication] beginBackgroundTaskWithName:#"backgroundTask"
expirationHandler:^{
watchKitHandler = UIBackgroundTaskInvalid;
}];
NSString *request = userInfo[#"request"];
if ([request isEqualToString:#"token"])
{
reply(#{#"token" : #"OK"});
[PSWatchNetworkOperations.shared loginUser];
}
dispatch_after( dispatch_time( DISPATCH_TIME_NOW, (int64_t)NSEC_PER_SEC * 1 ), dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
[[UIApplication sharedApplication] endBackgroundTask:watchKitHandler];
} );
}
This code just creates a background thread that forces iPhone to send a network request. Let's imagine you would have a special class in your iPhone app that would send these requests and send the answer to watch. For now, this is only accomplishable using App Groups. So you have to create an app group for your application and watchkit extension. Afterwards, I would recommend using MMWormhole in order to establish communication between your app and extension. The manual is pretty self-explaining.
Now what's the point of all this. You have to implement sending request to server and send response through wormhole. I use ReactiveCocoa, so example from my code is like this:
- (void)fetchShoppingLists
{
RACSignal *signal = [PSHTTPClient.sharedAPIClient rac_GET:#"list/my" parameters:#{#"limit":#20, #"offset":#0} resultClass:PSShoppingListsModel.class];
[signal subscribeNext:^(PSShoppingListsModel* shoppingLists) {
[self.wormHole passMessageObject:shoppingLists identifier:#"shoppingLists"];
}];
[signal subscribeError:^(NSError *error) {
[self.wormHole passMessageObject:error identifier:#"error"];
}];
}
As you see here I send back either response object, or error. Note, that all that you send through wormhole should be NSCoding-compatible.
Now on the watch you'll probably parse response like this:
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
PSWatchOperations.sharedInstance.requestUserToken()
PSWatchOperations.sharedInstance.wormhole.listenForMessageWithIdentifier("token", listener: { (messageObject) -> Void in
// parse message object here
}
})
}
So, to make a conclusion. You send request to parent application to wake up from background and start async operation. Send reply() back immediately. When you receive answer from operation send notification that you've got response. Meanwhile listen to response in your watchExtension.
Sorry, that was a lot of text, but I just hope it helps keep one's ass cool, because I've spent a lot of nerves on that.
May be you can try to explain the exact problem a little more clearly. But one thing you may want to do regardless is to make the openParentApp call in awakeWithContext: instead of willActivate.

CBCentralManager *manager EXC_BAD_ACCESS with iOS7.0

I just upgraded to Xcode V5.0 (5A1413) the build success but running the program against the emulator causes the error at the property definition:
#property (nonatomic, strong) CBCentralManager *manager; --> Thread 1:EXC_BAD_ACCESS (code=2, address=0x8)
I ran into the same issue and finally resorted to this:
UIDevice *currentDevice = [UIDevice currentDevice];
if ([currentDevice.model rangeOfString:#"Simulator"].location == NSNotFound) {
self.centralMgr = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}
On the Simulator, if I don't guard against creation of the CBCentralManager, I see centralManagerDidUpdateState: called with a CBCentralManager* that matches my strong property. It can be referenced and the state is CBCentralManagerStateUnsupported. That makes sense, but if I nil my strong manager property at that point (since I'm not going to be doing any BLE on a simulator that doesn't support it) I get the EXC_BAD_ACCESS. So, in the absence of a better answer, I suggest you simply guard against firing up the manager at all, as in my code above.

ARC Retain Cycle appears after updating to iOS 6.1

After updating to iOS 6.1, I'm getting this warning in AFImageRequestOperation.m and AFHTTPClient.m from AFNetworking framework:
Capturing 'operation' strongly in this block is likely to lead to a
retain cycle
Based on this answer, I can fix a retain cycle in ARC by using __weak variables. It is also says
Block will be retained by the captured object
Does anyone know how to solve this?
Thanks.
We are fortunate that XCode 4.6 is showing a warning to avoid this problem
It can be solved by providing a weak reference
AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
**__weak AFImageRequestOperation *tempRequestOperation = requestOperation;**
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
if (success) {
UIImage *image = responseObject;
if (imageProcessingBlock) {
dispatch_async(image_request_operation_processing_queue(), ^(void) {
UIImage *processedImage = imageProcessingBlock(image);
dispatch_async(**tempRequestOperation**.successCallbackQueue ?: dispatch_get_main_queue(), ^(void) {
success(operation.request, operation.response, processedImage);
});
});
} else {
success(operation.request, operation.response, image);
}
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (failure) {
failure(operation.request, operation.response, error);
}
}];
OK here was the problem. I was keep downloading the Master branch from GitHub and now that I tried downloading AFNetworking from here (version 1.1.0) it doesn't show me the warning anymore.
I don't why the latest commits were not included in the master branch when I downloaded but clearly they've solved these strong refs in blocks warnings while ago.
Always check the website to see the latest released version or sync the latest commit from GitHub :) (It wasn't showing anything in my iOS 6.0 apps but Xcode 4.6 just brought them up)

Resources