Integrate Box IOS sdk in my ios project - ios

I'm trying to integrate BOX V2 IOS SDk on my ios project , the integration is fine, but when I try to login , and after I enter my username and password and granted the access , I get a white screen , and the boxAPIAuthenticationDidSucceed method is not called , her is my code
the connexion Method :
-(void) connectToBox {
[BoxSDK sharedSDK].OAuth2Session.clientID = #"my-client-id";
[BoxSDK sharedSDK].OAuth2Session.clientSecret = #"my-client-secret";
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(boxAPIAuthenticationDidSucceed:)
name:BoxOAuth2SessionDidBecomeAuthenticatedNotification
object:[BoxSDK sharedSDK].OAuth2Session];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(boxAPIAuthenticationDidFail:)
name:BoxOAuth2SessionDidReceiveAuthenticationErrorNotification
object:[BoxSDK sharedSDK].OAuth2Session];
self.LoginCotroller = [[BoxAuthorizationViewController alloc] initWithAuthorizationURL:authorizationURL redirectURI:redirectURI];
[self presentViewController:self.LoginCotroller animated:YES completion:nil];
}
and I implement the two methods :
- (void)boxAPIAuthenticationDidSucceed:(NSNotification *)notification;
- (void)boxAPIAuthenticationDidFail:(NSNotification *)notification;
and the notifications methods :
#pragma mark - Handle OAuth2 session notifications
- (void)boxAPIAuthenticationDidSucceed:(NSNotification *)notification
{
BoxOAuth2Session *session = (BoxOAuth2Session *) notification.object;
NSLog(#"Received OAuth2 successfully authenticated notification");
NSLog(#"Access token (%#) expires at %#", session.accessToken, session.accessTokenExpiration);
NSLog(#"Refresh token (%#)", session.refreshToken);
dispatch_sync(dispatch_get_main_queue(), ^{
[self.LoginCotroller dismissViewControllerAnimated:YES completion:nil];
});
}
- (void)boxAPIAuthenticationDidFail:(NSNotification *)notification
{
NSLog(#"Received OAuth2 failed authenticated notification");
NSString *oauth2Error = [[notification userInfo] valueForKey:BoxOAuth2AuthenticationErrorKey];
NSLog(#"Authentication error (%#)", oauth2Error);
dispatch_sync(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES completion:nil];
});
}
I dont know what wrong with my code.So if any one can help.Thanks

I'd suggest adding your controller as an observer for BoxOAuth2SessionDidRefreshTokensNotification as well to call boxAPIAuthenticationDidSucceed: method. BoxOAuth2SessionDidRefreshTokensNotification is posted when a new access-token is created/refresed.

Related

Sinch VOIP calls between two different apps with different bundle IDs

I am trying to establish voip call through two different apps. Lets assume one is seller and another is customer. Seller app can only call, and customer app can only receive call. I have setup two apps with sinch applicationKey, secret, userID etc. As I want to receive call in customer app, I have generated VOIP certificate in Apple Dev Account for customer app's bundle id. And I have uploaded that certificate(p12) in Sinch Dashboard. I am using Managed Push in customer app.
But I am unable to receive push or calls in customer app.
I tried changing the bundle id of the two apps. When I keep the bundle id same for the two apps, it works like charm.
My question is, How can I make voip calls between two different apps with different bundle ids?
Here is my AppDelegate.m file codes, which works as it should when the bundle id is same:
#import "SINCallKitProvider.h"
#import "CallViewController.h"
#interface AppDelegate () <SINClientDelegate, SINCallClientDelegate, SINManagedPushDelegate>
#property (nonatomic, readwrite, strong) id<SINManagedPush> push;
#property (nonatomic, readwrite, strong) SINCallKitProvider *callKitProvider;
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(#"didFinishLaunchingWithOptions:");
[Sinch setLogCallback:^(SINLogSeverity severity, NSString *area, NSString *message, NSDate *timestamp) {
NSLog(#"[%#] %#", area, message);
}];
self.push = [Sinch managedPushWithAPSEnvironment:SINAPSEnvironmentAutomatic];
self.push.delegate = self;
[self.push setDesiredPushType:SINPushTypeVoIP];
self.callKitProvider = [[SINCallKitProvider alloc] init];
void (^onUserDidLogin)(NSString *) = ^(NSString *userId) {
[self initSinchClientWithUserId:userId];
};
[[NSNotificationCenter defaultCenter]
addObserverForName:#"UserDidLoginNotification"
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
NSString *userId = note.userInfo[#"userId"];
[[NSUserDefaults standardUserDefaults] setObject:userId forKey:#"userId"];
[[NSUserDefaults standardUserDefaults] synchronize];
onUserDidLogin(userId);
}];
[[NSNotificationCenter defaultCenter] addObserverForName:#"UserDidLogoutNotification"
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
_client = nil;
}];
return YES;
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
id<SINCall> call = [_callKitProvider currentEstablishedCall];
// If there is one established call, show the callView of the current call when
// the App is brought to foreground. This is mainly to handle the UI transition
// when clicking the App icon on the lockscreen CallKit UI.
if (call) {
UIViewController *top = self.window.rootViewController;
while (top.presentedViewController) {
top = top.presentedViewController;
}
// When entering the application via the App button on the CallKit lockscreen,
// and unlocking the device by PIN code/Touch ID, applicationWillEnterForeground:
// will be invoked twice, and "top" will be CallViewController already after
// the first invocation.
if (![top isMemberOfClass:[CallViewController class]]) {
[top performSegueWithIdentifier:#"callView" sender:call];
}
}
}
#pragma mark -
- (void)initSinchClientWithUserId:(NSString *)userId {
if (!_client) {
_client = [Sinch clientWithApplicationKey:#"<My key>"
applicationSecret:#"<My secret>"
environmentHost:#"clientapi.sinch.com"
userId:userId];
_client.delegate = self;
_client.callClient.delegate = self;
[_client setSupportCalling:YES];
[_client enableManagedPushNotifications];
_callKitProvider.client = _client;
[_client start];
// [_client startListeningOnActiveConnection];
}
}
- (void)handleRemoteNotification:(NSDictionary *)userInfo {
if (!_client) {
NSString *userId = [[NSUserDefaults standardUserDefaults] objectForKey:#"userId"];
if (userId) {
[self initSinchClientWithUserId:userId];
}
}
[self.client relayRemotePushNotification:userInfo];
}
#pragma mark - SINManagedPushDelegate
- (void)managedPush:(id<SINManagedPush>)managedPush
didReceiveIncomingPushWithPayload:(NSDictionary *)payload
forType:(NSString *)pushType {
NSLog(#"didReceiveIncomingPushWithPayload: %#", payload.description);
// Since iOS 13 the application must report an incoming call to CallKit if a
// VoIP push notification was used, and this must be done within the same run
// loop as the push is received (i.e. GCD async dispatch must not be used).
// See https://developer.apple.com/documentation/pushkit/pkpushregistrydelegate/2875784-pushregistry .
[self.callKitProvider didReceivePushWithPayload:payload];
dispatch_async(dispatch_get_main_queue(), ^{
[self handleRemoteNotification:payload];
[self.push didCompleteProcessingPushPayload:payload];
});
}
#pragma mark - SINCallClientDelegate
- (void)client:(id<SINCallClient>)client didReceiveIncomingCall:(id<SINCall>)call {
// Find MainViewController and present CallViewController from it.
UIViewController *top = self.window.rootViewController;
while (top.presentedViewController) {
top = top.presentedViewController;
}
[top performSegueWithIdentifier:#"callView" sender:call];
}
- (void)client:(id<SINClient>)client willReceiveIncomingCall:(id<SINCall>)call {
[self.callKitProvider willReceiveIncomingCall:call];
}
#pragma mark - SINClientDelegate
- (void)clientDidStart:(id<SINClient>)client {
NSLog(#"Sinch client started successfully (version: %#)", [Sinch version]);
}
- (void)clientDidFail:(id<SINClient>)client error:(NSError *)error {
NSLog(#"Sinch client error: %#", [error localizedDescription]);
}
#end

VOIP Sinch in iOS 11 not work in background

I use Sinch VOIP to make calling between App-To-App in iOS 11.1.2
Work well when the application status is foreground but in background and terminated nothing happened after I open the application console print
Pubnub request SCHEDULED (ID=081E49C2-C30A-4B4B-840C-E6A6051E6F44, URL=https://rebtelsdk.pubnub.com/subscribe/sub-c-c5e52f20-d446-11e3-b488-02ee2ddab7fe/5e1e1309-136a-40d4-935f-2627ebe4e8f2B/0/0, NST-VoIP: NO)
Pubnub request STARTED (ID=081E49C2-C30A-4B4B-840C-E6A6051E6F44)
Pubnub request SUCCESS (ID=081E49C2-C30A-4B4B-840C-E6A6051E6F44):
(
(
),
15117251992031337
)
onPubSubSubscriptionSuccess: userInfo: {
channel = "5e1e1309-136a-40d4-935f-2627ebe4e8f2B";
subscribeSequence = 1;
timetoken = 0;
useVoIPNetworkServiceType = 0;
}
I upload VOIP & APNS certificates to Sinch dashboard and I used SINManagedPush & PushKit My code is
Setup Push Manager & SINClient in didFinishLaunchingWithOptions
self.push = [Sinch managedPushWithAPSEnvironment:SINAPSEnvironmentAutomatic];
self.push.delegate = self;
[self.push setDesiredPushTypeAutomatically];
void (^onUserDidLogin)(NSString *) = ^(NSString *userId) {
[self.push registerUserNotificationSettings];
[self initSinchClientWithUserId:userId];
};
[[NSNotificationCenter defaultCenter]
addObserverForName:#"UserDidLoginNotification"
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
NSString *userId = note.userInfo[#"userId"];
[[NSUserDefaults standardUserDefaults] setObject:userId forKey:#"userId"];
[[NSUserDefaults standardUserDefaults] synchronize];
onUserDidLogin(userId);
}];
- (void)initSinchClientWithUserId:(NSString *)userId {
if (!_client) {
_client = [Sinch clientWithApplicationKey:#"APP-Key"
applicationSecret:#"APP-Secret"
environmentHost:#"sandbox.sinch.com"
userId:userId];
_client.delegate = self;
_client.callClient.delegate = self;
[_client setSupportCalling:YES];
[_client enableManagedPushNotifications];
[_client start];
[_client startListeningOnActiveConnection];
_callKitProvider = [[SINCallKitProvider alloc] initWithClient:_client];
}
}
Get Device Token
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[self.push application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{
NSLog(#"User Info : %#",notification.request.content.userInfo);
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
[self.push application:[UIApplication sharedApplication] didReceiveRemoteNotification:notification.request.content.userInfo];
}
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{
NSLog(#"User Info : %#",response.notification.request.content.userInfo);
completionHandler();
[self.push application:[UIApplication sharedApplication] didReceiveRemoteNotification:response.notification.request.content.userInfo];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[self.push application:application didReceiveRemoteNotification:userInfo];
}
PushKit
-(void)voipRegistration
{
PKPushRegistry* voipRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
voipRegistry.delegate = self;
voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
}
-(void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type
{
[_client registerPushNotificationData:credentials.token];
}
-(void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(PKPushType)type{
NSLog(#"invalidated");
}
4.Call voipRegistration when SINClient start
- (void)clientDidStart:(id<SINClient>)client {
NSLog(#"Sinch client started successfully (version: %#)", [Sinch version]);
[self voipRegistration];
}
5.Implement SINManagedPushDelegate & SINCallClientDelegate
- (void)client:(id<SINCallClient>)client didReceiveIncomingCall:(id<SINCall>)call {
UIViewController *top = self.window.rootViewController;
while (top.presentedViewController) {
top = top.presentedViewController;
}
[top performSegueWithIdentifier:#"callView" sender:call];
}
- (SINLocalNotification *)client:(id<SINClient>)client localNotificationForIncomingCall:(id<SINCall>)call {
SINLocalNotification *notification = [[SINLocalNotification alloc] init];
NSArray * ansAr = #[#"رد",#"Answer"];
NSArray * MsgAr = #[[NSString stringWithFormat:#"مكالمة لم يرد عليها من %#", [call remoteUserId]],[NSString stringWithFormat:#"Incoming call from %#", [call remoteUserId]]];
notification.alertAction = ansAr[self.languageID];
notification.alertBody = MsgAr[self.languageID];
return notification;
}
- (void)client:(id<SINClient>)client willReceiveIncomingCall:(id<SINCall>)call {
[self.callKitProvider reportNewIncomingCall:call];
}
These is the code , Please help me if I forgot anything.
I checked the credentials.token is not null.
Thank you for your help.
When you setup the Sinch managed push with the code below:
self.push = [Sinch managedPushWithAPSEnvironment:SINAPSEnvironmentAutomatic];
self.push.delegate = self;
[self.push setDesiredPushTypeAutomatically];
The Sinch SDK will automatically do all the PushKit registration for you. So step 3 and 4 in your description is not necessary and should not be there. Part of the code in step 2 is not needed as well. Please take a look at the Sinch CallKit sample app from the SDK download package, and refer to the implementation of that App.
Below is a demo video made with the 3.12.4 Sinch SDK CallKit Sample App without any tweak, the device used in the demo is an iPhone7 running iOS 11, it gets the incoming call in background, killed and lockscreen mode:
Sinch CallKit Sample App Demo Video
Also, note that callKit only works with VoIP push, have you uploaded the right type of push certificate to Sinch Portal?
When you force kill an app apple wont wake the app for VoIP push, if you just have in background or reboot the phone apple will wake it up. Annoying, but that's apple

Share kit integration into iOS - Dropbox Authentication on button press

I’m trying to adapt the original Sharekit demo app so that it allows me to authenticate dropbox on a single button press (instead of appearing a new view etc. like it does in the demo).
To do this I have wired up a button with the following method as the IBAction (in the initial ViewController it launches into on Storyboard):
-(IBAction)assignDropbox:(id)sender
{
[SHK setRootViewController:self];
Class sharerClass = NSClassFromString(#"SHKDropbox");
BOOL isiOSSharer = [sharerClass isSubclassOfClass:[SHKiOSSharer class]];
if ([sharerClass isServiceAuthorized]) {
if (isiOSSharer) {
[sharerClass getUserInfo];
UIAlertView *iosSharerAlert = [[UIAlertView alloc] initWithTitle:#"iOS Social.framework sharer"
message:#"You can deauthorize this kind of sharer in settings.app, not here. By tapping this button you have refetched user info data only."
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:#"OK", nil];
[iosSharerAlert show];
} else {
[sharerClass logout];
//[self.tableView reloadData];
}
} else {
SHKSharer *sharer = [[sharerClass alloc] init];
[sharer authorize];
if (isiOSSharer) {
UIAlertView *iosSharerAlert = [[UIAlertView alloc] initWithTitle:#"iOS Social.framework sharer"
message:#"You can authorize this kind of sharer in settings.app, not here."
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:#"OK", nil];
[iosSharerAlert show];
}
}
if ([sharerClass isServiceAuthorized]) {
NSLog(#"After Logging in Username: %#", [sharerClass username]);
} else {
NSLog(#"After Logging in Username: %#", [sharerClass username]);
}
}
I’ve added the following notification code ViewDidLoad of the ViewController:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(authDidFinish:)
name:#"SHKAuthDidFinish"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(sendDidCancel:)
name:#"SHKSendDidCancel"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(sendDidStart:)
name:#"SHKSendDidStartNotification"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(sendDidFinish:)
name:#"SHKSendDidFinish"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(sendDidFailWithError:)
name:#"SHKSendDidFailWithError"
object:nil];
With the following code within the actual main (to make the notifications actually work - as per setup):
- (void)authDidFinish:(NSNotification*)notification
{
NSDictionary *userInfo = notification.userInfo;
NSNumber *success = [userInfo objectForKey:#"success"];
if (NO == [success boolValue]) {
NSLog(#"authDidFinish: NO");
} else {
NSLog(#"authDidFinish: YES");
NSLog(#"userInfo: %#", userInfo);
}
}
- (void)sendDidCancel:(NSNotification*)notification
{
NSLog(#"sendDidCancel:");
}
- (void)sendDidStart:(NSNotification*)notification
{
NSLog(#"sendDidStart:");
}
- (void)sendDidFinish:(NSNotification*)notification
{
NSLog(#"sendDidFinish:");
}
- (void)sendDidFailWithError:(NSNotification*)notification
{
NSLog(#"sendDidFailWithError:");
}'
It launches the web view in the app, and I can authenticate (I get notifications from dropbox saying another device has logged on), however the save authentication/session code in ‘SHKDropbox.m’ is never called.
Method under:
- (void)restClient:(DBRestClient*)client loadedAccountInfo:(DBAccountInfo*)info
I’ve done a lot of comparison work to see what the differences are between the projects, but can’t see any difference in settings.
Have you got any storyboard/button presses sample code as described above. Or have you got any idea on why this isn’t working on ShareKit?

PushNotification redirect to respected viewcontroller

I am using push notification in my application. My question is, if user receives a push notification out of the app, user should be able to click that notification banner and be
brought to the activities page where notification is displayed.
Anybody can help me how to solve this issue. I am new in push notification.
//Use this code in your AppDelegate.m
-(void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)userInfo
{
//code for navigate to viewcontroller
ActivityViewController *objActivity = [[ActivityViewController alloc] initWithNibName:#"ActivityViewController" bundle:nil];
[self.navigationcontroller pushViewController: objActivity animated:YES];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
NSString *aPayload=[userInfo objectForKey:#"payload"];
NSDictionary *JSON =
[NSJSONSerialization JSONObjectWithData: [aPayload dataUsingEncoding:NSUTF8StringEncoding]
options: NSJSONReadingMutableContainers
error: NULL];
if ([[JSON objectForKey:#"activity"]isEqualToString:#"encore"]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Piggyback"
message: [[userInfo objectForKey:#"aps"] objectForKey:#"alert"]
delegate: nil
cancelButtonTitle:#"DONE"
otherButtonTitles: nil];
self.likeBedge=self.likeBedge+1;
[alert show];
[[NSNotificationCenter defaultCenter] postNotificationName:#"likeComment" object:self userInfo:userInfo];
}
else if ([[JSON objectForKey:#"activity"]isEqualToString:#"like"]||[[JSON objectForKey:#"activity"]isEqualToString:#"comment"]){
self.likeBedge=self.likeBedge+1;
[[NSNotificationCenter defaultCenter] postNotificationName:#"likeComment" object:self userInfo:userInfo];
}
else if ([[JSON objectForKey:#"activity"]isEqualToString:#"started playing"]){
self.postBedge=self.postBedge+1;
NSLog(#"%d",self.postBedge);
[[NSNotificationCenter defaultCenter] postNotificationName:#"started playing" object:self userInfo:userInfo];
}
else if ([[JSON objectForKey:#"activity"]isEqualToString:#"stopped playing"]){
[[NSNotificationCenter defaultCenter] postNotificationName:#"stopped playing" object:self userInfo:userInfo];
}
else if ([[JSON objectForKey:#"activity"]isEqualToString:#"#user play"]||[[JSON objectForKey:#"activity"]isEqualToString:#"#user comment"]){
[[NSNotificationCenter defaultCenter] postNotificationName:#"likeComment" object:self userInfo:userInfo];
}
return;
}
i have already done this above code but when app is in background and if notification is come user tap on banner it should redirect to activity page
So when the application goes to background and you receive a notification the method you are going to call in appdelegate.m file is
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
// Here present the class you want
}

MCSession ofen can't reconnect when app return to foreground from background

I'm using Mutipeer Connectivity to make a chat app. At first, everything worked well and MCSession can connect with each other. But when user tap home button and then tap app icon, the apps disconnect with each other and often can't reconnect. But sometimes it can reconnect. The success is random.
- (void)viewDidLoad
{
[super viewDidLoad];
...
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(DidBecomeActive:)
name: UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(didEnterBackground:)
name: UIApplicationDidEnterBackgroundNotification object:nil];
NSString *displayname=[[NSUUID UUID] UUIDString];
_MyPeerID=[[MCPeerID alloc] initWithDisplayName:displayname];
}
- (void)DidBecomeActive:(NSNotification *)notification
{
if (notFirstLaunch==YES) {
NSLog(#"DidBecomeActive");
NSString *displayname=[[NSUUID UUID] UUIDString];
_MyPeerID=[[MCPeerID alloc] initWithDisplayName:displayname];
[self createSession];
[self createAdvertiser];
[self beginBrowsing];
}
notFirstLaunch=YES;
}
- (void)didEnterBackground:(NSNotification *)notification
{
NSLog(#"didEnterBackground");
[_MySession disconnect];
_MySession=nil;
_MyBrowser=nil;
_MyAdver=nil;
}
- (void)createSession
{
_MySession=[[MCSession alloc] initWithPeer:_MyPeerID];
_MySession.delegate=self;
}
- (void)createAdvertiser
{
_MyAdver=[[MCNearbyServiceAdvertiser alloc] initWithPeer:_MyPeerID discoveryInfo:nil serviceType:MyServiceType];
_MyAdver.delegate=self;
[_MyAdver startAdvertisingPeer];
}
- (void)beginBrowsing {
_MyBrowser=[[MCNearbyServiceBrowser alloc] initWithPeer:_MyPeerID serviceType:MyServiceType];
_MyBrowser.delegate=self;
[_MyBrowser startBrowsingForPeers];
}
Judging by the code you've posted, nothing reconnects because in didEnterBackground you disconnect from the session and destroy the session, browser and advertiser. In DidBecomeActive you have a guard (notFirstLaunch) that means that the session and advertiser are only created the first time you become active, and NOT after you become active when you come back from being in the background.

Resources