Failed to get voip phone information from native phone recents by using CallKit - objective-c

I integrated CallKit framework to my app, and make an outgoing call.
I can see the outgoing call in native phone recents.
But when I tab the outgoing call and want to get phone info.
It crashed.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSUserActivity interaction]: unrecognized selector sent to instance 0x17d4ab90'
Here is my code in AppDelegate.m
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray * __nullable restorableObjects))restorationHandler NS_AVAILABLE_IOS(8_0)
{
INInteraction *interaction = userActivity.interaction;
INStartAudioCallIntent *startAudioCallIntent = (INStartAudioCallIntent *)interaction.intent;
INPerson *contact = startAudioCallIntent.contacts[0];
INPersonHandle *personHandle = contact.personHandle;
NSString *phoneNumber = personHandle.value;
}
I crashed in INInteraction *interaction = userActivity.interaction;
And I checked with interaction info
#property (readonly, nullable, NS_NONATOMIC_IOSONLY) INInteraction *interaction API_AVAILABLE(macosx(10.12), ios(10.0));
Following are my environment
mac: 10.12.1
xcode: 8.1
iOS: 10.1.1
It doesn't violate the requirement
I search all day but seems no one meet this problem.
Is there anything wrong about code level or have another way to get the phone information?

enter image description here
I have try add NSUserActivity Types bu it not used, I also Use This method sovle This problem.
I can fixed this with adding intents.framework in Target->Build Phases-> Link Binary with Libraries
enter image description here

I hope you missed out NSUserActivityTypes key in info.plist. Below is the key and value to add, based on the intent you are handling,

Related

Sometimes console.log shows in log-ios sometimes it doesn't

I have run react-native start in one terminal, and then react-native ios-run in another. My initial console.log rarely show, sometimes they do.
Lot's of times, randomly I do see:
LOG MESSAGE QUOTA EXCEEDED - SOME MESSAGES FROM THIS PROCESS HAVE BEEN DISCARDED
Are my console.log's being discarded? I tried clearing the console to see it more clearly but I can't find a way to clear console either.
On Android, I wouldn't have issue with missing console.log.
react-native logs information using syslog daemon. This daemon attempts to prevent spamming to the log (DoS attack). These limits are set on per process basis.
The simple solution is to stop/start simulator and you will be obtain new process that is not limited by the previous behaviour.
The other solution is to disable syslogd limits what will be heavilly depends on your operation system.
i found that the JavascriptCore engine won't automatically redirect the console.log to either XCode output panel or the system builtin Console.App, not to mention the self-broken log-ios command.
the only way to see console.log without remote debugging in browser is redirect(bind) it ourselves:
//Add this headers
#import <JavaScriptCore/JavaScriptCore.h>
#import <jschelpers/JavaScriptCore. h>
#import <React/RCTBridge+Private.h>
...
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
...
...
[self.window makeKeyAndVisible];
::sleep(2); //<---!!!!!see below
JSGlobalContextRef globalContext = rootView.bridge.jsContextRef;
JSContext *context = [JSC_JSContext(globalContext) contextWithJSGlobalContextRef:globalContext];
context[#"console"][#"log"] = ^(NSString *message) {
NSLog(#"Javascript log: %#",message);
};
return YES;
}
Caution: the JSContext within reactInstance is created in another thread, I don't know how to get the loaded event(in only my project, since i don't like to modify the react-native engine), just wait sometime here for testing purpose.

NSHealthShareUsageDescription must be set in the app's Info.plist in order to request read authorization

I have a framework that uses
_healthStore requestAuthorizationToShareTypes:writeTypes readTypes:readTypes completion:^(BOOL success, NSError *error) {
When I include the framework into my iOS app and put the following in my app info.plist file
<key>NSHealthShareUsageDescription</key>
<string>Read heart rate monitor data.</string>
<key>NSHealthUpdateUsageDescription</key>
<string>Share workout data with other apps.</string>
everything works fine - not including those keys results in the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSHealthShareUsageDescription must be set in the app's Info.plist in order to request read authorization.'
My problem is that when running the unit tests for the framework it crashes with the above error. I've put the keys in all of the info.plist files for the framework and for the test target but still get the crash.
Which plist file should the keys go into in order to run the test target?
(should also mention that I'm in the process of switching over to Swift3 - this is part of the project that is in Objective-C - prior to iOS10 and XCode 8 this all worked fine).
I've created a framework with appropriate unit test to show the problem: https://github.com/asensei/HKHealthStoreFrameworkUnitTestBug
You must add the NSHealthShareUsageDescription and NSHealthUpdateUsageDescription keys to the Info.plist file in your application. You do this by:
Clicking on the "Info.plist" file
Right clicking the screen and select add rows.
scroll to "Privacy - Health Share.. " and "Privacy - Health Update.. "
Select both of those and you should be good.
You have to add two descriptions NSHealthUpdateUsageDescription and NSHealthShareUsageDescription, and then give each of them a description. See screenshot below.

String with unicode doesn't match on new XCode UI Test and the test fails

I was making some UI Tests using the new XCode 7. How my app uses Notification, on first use iOS automatically ask '"MyApp" Would Like to Send You Notifications'.
When I record the test, XCode write these lines below:
- (void)testFirstUse {
[XCUIDevice sharedDevice].orientation = UIDeviceOrientationPortrait;
XCUIApplication *app = [[XCUIApplication alloc] init];
[app.alerts[#"\U201cMyApp\U201d Would Like to Send You Notifications"].collectionViews.buttons[#"OK"] tap];
[app.tables/*#START_MENU_TOKEN#*/.staticTexts[#"United States"]/*[[".cells.staticTexts[#\"United States\"]",".staticTexts[#\"United States\"]"],[[[-1,1],[-1,0]]],[0]]#END_MENU_TOKEN#*/ tap];
[app.navigationBars[#"Select a Country"].buttons[#"Next"] tap];
}
Note that XCode puts the unicode instead of quotes signal on MyApp name.
When a run the test fails with error "No matches found for alert".
I tried change the unicode to quote signal but it also doesn't work.
Is it clear?
Had someone this same issue?
[Update]
I have two issue on this code
1- There is a bug on message with unicodes generated by XCode
2- Test fails after tap on Alerts showed by system
I found one work around for avoid crashing after dismissing a system alert:
I changed this line
[app.alerts[#"\U201cMyApp\U201d Would Like to Send You Notifications"].collectionViews.buttons[#"OK"] tap];
to
XCUIElement *alert = app.alerts[#"\U0000201cMyApp\U0000201d Would Like to Send You Notifications"].collectionViews.buttons[#"OK"];
if ([alert exists]) {
[alert tap];
}
I made two changes
the four 0000 on unicodes in order to avoid build failed
And the a validation before tap on alert to avoid test failed
You can acknowledge the alert by directly accessing the alert.element and tapping the "OK" button via the collection view.
let app = XCUIApplication()
app.launch()
// trigger location permission dialog
app.alerts.element.collectionViews.buttons["Allow"].tap()
However, Xcode 7 (and Xcode 7.1 Beta) will crash after successfully dismissing the alert. I've opened a bug report with Apple and encourage all those experiencing the problem to duplicate it.
The format of unicode characters generated by xcode is wrong so it is xcode bug. As a temporary workaround you could replace
[app.alerts[#"\U201cMyApp\U201d Would Like to Send You Notifications"].collectionViews.buttons[#"OK"] tap];
with
[app.alerts[#"\u201cMyApp\u201d Would Like to Send You Notifications"].collectionViews.buttons[#"OK"] tap];
i.e. all \U on \u

XPCService not getting launched from app

I am trying a simple sample app on XPCServices, in which I am following below steps:
Step 1: Created a sample project and added target - XPCServices with name - HelperProcess to it. When the target is created XCode automatically generates below files:
HelperProcessProtocol.h
HelperProcess.h
HelperProcess.m
main.m
Step 2: In main.m added a log statement within implementation of ServiceDelegate:
- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
// This method is where the NSXPCListener configures, accepts, and resumes a new incoming NSXPCConnection.
NSLog(#"Log which is never displayed :(");
// Configure the connection.
// First, set the interface that the exported object implements.
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:#protocol(HelperProcessProtocol)];
// Next, set the object that the connection exports. All messages sent on the connection to this service will be sent to the exported object to handle. The connection retains the exported object.
HelperProcess *exportedObject = [HelperProcess new];
newConnection.exportedObject = exportedObject;
// Resuming the connection allows the system to deliver more incoming messages.
[newConnection resume];
// Returning YES from this method tells the system that you have accepted this connection. If you want to reject the connection for some reason, call -invalidate on the connection and return NO.
return YES;
}
Step 3: In AppDelegate added below code in applicationDidFinishLaunching:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
_connectionToService = [[NSXPCConnection alloc] initWithServiceName:#"HelperProcess"];
_connectionToService.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:#protocol(HelperProcessProtocol)];
[_connectionToService resume];
}
Problem is -
When I launch the app, neither the log added in
listener:shouldAcceptNewConnection: is displayed nor the helper
process appears in Activity Monitor :(
Here is the code: XPCShootOut
Note: I am trying this on XCode 6.0
Is there any additional setup which I need to do to make it working? Please suggest.
-- Update --
I tried to refer this sample from apple: AppSandboxLoginItemXPCDemo
When I tried to run it on XCode 6, it displayed error message - 'No signing identity found'. Since I don't have registered mac developer account, in build settings for - iDecide and iDecideHelper I changed 'Code Signing Identity' as 'Don't Code Sign'.
I got a warning for each of the targets:
Code Sign warning: CODE_SIGN_ENTITLEMENTS specified without specifying CODE_SIGN_IDENTITY. It is not possible to add entitlements to a binary without signing it.
This time when I compiled the build, it worked as expected.
Now I tried to follow the steps specified in its ReadMe.txt file, specifically I performed these steps in my sample app:
Step 1: Updated - Main App Target -> Capabilities Tab
Turned on 'App Sandbox'
Turned on 'App Groups'
Added an app group - 'XYZ'
Step 2: Updated - Helper Target -> Capabilities Tab
Turned on 'App Sandbox'
Enabled 'Outgoing Connections (Client)'
Turned on 'App Groups'
Added an app group - 'XYZ'
Step 3: Updated - Helper Target -> General Tab -> Bundle Identifier, added 'XYZ' prefix to it.
On running the app in console it displayed these messages:
10/12/14 6:27:42.159 PM xpcd[554]: (null): Code identity[pid: 11875::Devarshi-Kulshreshtha.XPCShootOut (/Users/devarshi/Library/Developer/Xcode/DerivedData/XPCShootOut-aaedwraccpinnndivoaqkujcmhmj/Build/Products/Debug/XPCShootOut.app)] is not in ACL for container: ~/Library/Containers/Devarshi-Kulshreshtha.XPCShootOut/Data -- allowing access.
10/12/14 6:27:43.712 PM appleeventsd[63]: <rdar://problem/11489077> A sandboxed application with pid 11875, "XPCShootOut" checked in with appleeventsd, but its code signature could not be validated ( either because it was corrupt, or could not be read by appleeventsd ) and so it cannot receive AppleEvents targeted by name, bundle id, or signature. Error=ERROR: #100013 { "NSDescription"="SecCodeCopySigningInformation() returned 100013, -." } (handleMessage()/appleEventsD.cp #2072) client-reqs-q
Neither app performed its intended function nor it displayed the log message added in listener:shouldAcceptNewConnection: delegate.
I am clueless. Kindly suggest if I am missing any thing? Is it possible to get XPC service sample app working without a registered mac developer account?
I don't think you can launch XPC services without having them signed.
Even for testing and debugging the code sign build infrastructure needs to be setup.
I think the Mac developer certificate is free you don't need a paid account for that.

Testing internet connection on iPad app using ios5

I have been searching through the forum regarding how to check whether there is internet or not in my ipad app. I just created a simple webview project with other view controllers and I need to display a UIAlert message when the internet is not available. In my case it is displaying the message when I run the app. When I run the app with internet and then deactivate the internet, it does not show the UIAlert message, that is if I switch between the views, it does not any more show the no internet connection.
I have followed this way of implementation in my project: (sorry my mistake this is the link I followed) http://mozymac.com/forums/f54/how-check-if-there-internet-connection-iphone-os-devices-595/ [This is the new edited question]
Apart from that I went through some of the previous questions in Stackoverflow forum like for ex: How to check for an active Internet connection on iOS or OSX?
But everybody has their own version. If any one has a much more updated method for ios5, xcode 4.2.1 of how to accomplish this then would be helpful for me.
Thanks
Is there a reason why you want to check for internet connection before actually trying to load a request in the UIWebView?
Best practice is to just start loading, and use your UIWebViewDelegate/NURLConnectionDelegate to inspect the NSError to see what is wrong. In case of network failure you will receive an error with a domain equal to NSURLErrorDomain. The error code will indicate what the problem is, see the NSError codes enum.
And only after the first error start your reachability to see when the internet connection becomes available again. Or easier, just let the user retry.
Using the Reachability code will actually cause some overhead. It takes time to check if the internet is available, which you could just have used to set up the actual connection as well.
Example
Since you are using a UIWebView you should implement the following delegate method to be notified of errors.
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
if (![[error domain] isEqualToString:NSURLErrorDomain]) {
// not a nsurl error, take other appropriate action
return;
}
NSInteger code = [error code];
// show appropriate error to user, based on code
}
In this delegate method you should do whatever is needed to achieve what you want. You could retry the request yourself, show a message to the user or start listening for reachability changes using the code from the Reachability example provided by Apple.
Apple has one, it's called Reachability. Here's the link to it.
http://developer.apple.com/library/ios/ipad/#samplecode/Reachability/Introduction/Intro.html
Best way to check internet connection is Reachibility application
link
Or else
+ (BOOL)isNetworkAvailable
{
CFNetDiagnosticRef diag;
diag = CFNetDiagnosticCreateWithURL (NULL, (CFURLRef)[NSURL URLWithString:#"www.apple.com"]);
CFNetDiagnosticStatus status;
status = CFNetDiagnosticCopyNetworkStatusPassively (diag, NULL);
CFRelease (diag);
if ( status == kCFNetDiagnosticConnectionUp )
{
//NSLog (#"Connection is up");
return YES;
} else {
NSLog (#"Connection is down");
return NO;
}
}