Updating in response to some PR comments. This commit

1.Changes the name of the APNSToken and the setter for it.
2. Updates the license files to be actually correct.
This commit is contained in:
AdamCrabtreeMSFT 2020-01-03 11:23:44 -08:00
Родитель f1947a8956
Коммит 6ac376c696
16 изменённых файлов: 58 добавлений и 82 удалений

Просмотреть файл

@ -1,24 +1,31 @@
# Microsoft Graph notifications SDK
Using the new and improved, lightweight Microsoft Graph notifications client SDK within your application, you can update the state of a notification and sync that state across all endpoints. With the client-side SDK, your app will initiate a subscription with the Microsoft Graph notification service. This allows your app to start receiving notifications that are published by your application server & targeted at the currently signed-in user. The SDK then manages the notifications on the client side, including receiving new incoming notifications, managing the state of notifications for scenarios like universal dismiss, as well as retrieving full notification history.
# Sample App for running the Microsoft Graph notifications client library in your iOS application
> **Note:** The preview version of the Web SDK is now available and we welcome your feedback. The client SDKs for Windows, iOS and Android platforms are coming shortly so please check back soon for updates. In the meantime, you can alternatively target these platforms using the cross-device, [Project Rome SDK](https://developer.microsoft.com/en-us/windows/project-rome).
## Getting Started
## [Documentation wiki](https://github.com/microsoft/MSGraphNotifications/wiki)
Learn more about how to use the Graph notifications client SDK here: https://github.com/microsoft/MSGraphNotifications/wiki
### Prerequisites
## Privacy
See [Microsoft's privacy statement](https://privacy.microsoft.com/en-us/privacystatement/) for more information.
1. Have xCode and Cocoapods installed installed. More details [here](https://cocoapods.org/)
## Contributing
### Building the sample
1. ``pod install`` (from directory of podfile)
2. ``build from xCode``
This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
### Running the sample
1. Build the sample (if is not built already).
1. Initialize and setup MSAL using the directions given [here](https://github.com/AzureAD/microsoft-authentication-library-for-objc)
1. Set the following values:
- ``APPLICATION_CLIENT_ID`` in Secrets.h: this is the client ID of your Azure AD client app
- ``APP_HOST_NAME`` in secrets.h: this is the "cross-device domain name" that you have registered
and verified in your Cross-Device App registration in Partner Center (https://partner.microsoft.com/dashboard )
2. Sign in with an Azure AD or MSA account.
3. Click Subscribe, then grant permissions for the iOS app to read and write notifications.
4. Click the other buttons to exercise the various functions.
5. Post a new notification from Graph explorer and see a notification popup. Click the popup to be redirected to https://docs.microsoft.com/en-us/graph/notifications-concept-overview
## Other tips
When you submit a pull request, a CLA bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.
1. Getting duplicate push notifications? This is a known server-side issue in some cases.
See the [README for the client itself](https://www.npmjs.com/package/@microsoft/user-notifications-client) to learn more. Look for the text starting with:
> userNotificationApiImpl.processPushNotificationAsync(notificationPayload) may call back to the Graph notification server to fetch notification data
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
1. To look at the logs of the sample app and the client library, the best way to do it is to set the xCode environment variable
``CFNETWORK_DIAGNOSTICS`` = 3

1
iOS/.gitignore поставляемый
Просмотреть файл

@ -4,6 +4,7 @@
## User settings
xcuserdata/
*.xcworkspace/
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint

Просмотреть файл

@ -1,6 +1,4 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. Licensed under the MIT license.
#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>

Просмотреть файл

@ -1,6 +1,4 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. Licensed under the MIT license.
#import "AppDelegate.h"
#import <GraphNotificationsLibrary/UserNotificationApi.h>
@ -62,7 +60,7 @@
NSLog(@"GraphNotificationsSample APNs token: %@", deviceTokenStr);
@try {
[GlobalApnsToken setGlobalApnsToken:deviceTokenStr];
[GlobalApnsToken setApnsDeviceToken:deviceTokenStr];
} @catch (NSException* exception) {
NSLog(@"Failed to update notification registration with exception %@", exception);
}

Просмотреть файл

@ -1,6 +1,4 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. Licensed under the MIT license.
#ifndef APNSToken_h
@ -8,7 +6,7 @@
@interface GlobalApnsToken: NSObject
+(NSString *) apnsDeviceToken;
+(void) setGlobalApnsToken:(NSString*)apnsToken;
+(void) setApnsDeviceToken:(NSString*)apnsToken;
@end
#endif /* APNSToken_h */

Просмотреть файл

@ -1,25 +1,23 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. Licensed under the MIT license.
#import <Foundation/Foundation.h>
#import "GlobalApnsToken.h"
@implementation GlobalApnsToken
static NSString *g_apnsToken = 0;
static NSString *apnsToken = 0;
+(NSString *) apnsDeviceToken {
@synchronized ([GlobalApnsToken class]) {
if (!g_apnsToken)
if (!apnsToken)
{
g_apnsToken = [NSString string];
apnsToken = [NSString string];
}
return g_apnsToken;
return apnsToken;
}
}
+(void) setGlobalApnsToken:(NSString*)apnsToken
+(void) setApnsDeviceToken:(NSString*)apnsToken
{
g_apnsToken = apnsToken;
apnsToken = apnsToken;
}
@end

Просмотреть файл

@ -1,6 +1,4 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. Licensed under the MIT license.
#pragma once

Просмотреть файл

@ -1,6 +1,4 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. Licensed under the MIT license.
#import "LoginViewController.h"
#import <MSAL/MSAL.h>
@ -98,27 +96,17 @@ typedef NS_ENUM(NSInteger, LoginState) {
if (state == SIGNED_OUT) {
[self _setStatusText:@"Signing in AAD..."];
NSError* msalError = [[NSError alloc] init];
MSALAuthority* authority = [MSALAuthority authorityWithURL:[NSURL URLWithString:@"https://login.microsoftonline.com/common/oauth2"] error:&msalError];
MSALPublicClientApplicationConfig *config = [[MSALPublicClientApplicationConfig alloc] initWithClientId:APPLICATION_CLIENT_ID];
NSArray<NSString *> *scopes = @[@"https://activity.microsoft.com/UserActivity.ReadWrite.CreatedByApp", @"https://activity.microsoft.com/Notifications.ReadWrite.CreatedByApp"];
MSALWebviewParameters* params = [[MSALWebviewParameters alloc] initWithParentViewController:self];
MSALPublicClientApplication *application = [[MSALPublicClientApplication alloc] initWithConfiguration:config error:&msalError];
MSALInteractiveTokenParameters *interactiveParams = [[MSALInteractiveTokenParameters alloc] initWithScopes:scopes webviewParameters:params];
interactiveParams.authority = authority;
interactiveParams.promptType = MSALPromptTypeSelectAccount;
[application acquireTokenWithParameters:interactiveParams completionBlock:^(MSALResult *result, NSError *error) {
[self loginInternal:AAD finishBlock:^(NSError *error, NSString* accessToken) {
if (!error)
{
// You'll want to get the account identifier to retrieve and reuse the account
// for later acquireToken calls
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.manager = [appDelegate.manager initWithAccount:result.accessToken];
appDelegate.manager = [appDelegate.manager initWithAccount:accessToken];
if(appDelegate.manager)
{
[self _setButtonTextAndVisibilityForState:MSA];
[self _setState:MSA];
[self _setButtonTextAndVisibilityForState:AAD];
[self _setState:AAD];
}
else
{
@ -127,13 +115,14 @@ typedef NS_ENUM(NSInteger, LoginState) {
}
else
{
[self _setStatusText:[NSString stringWithFormat:@"MSA sign-in failed with error %@", error]];
[self _setStatusText:[NSString stringWithFormat:@"AAD sign-in failed with error %@", error]];
}
}];
} else {
//NOTE: Sign out is currently not supported in the MSAL library. See the issue here. The token can be removed from the cache but that is not being shown.
//https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/589
}
}
- (LoginState)_getState {

Просмотреть файл

@ -1,6 +1,4 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. Licensed under the MIT license.
#pragma once

Просмотреть файл

@ -1,6 +1,5 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. Licensed under the MIT license.
#import "NotificationsManager.h"
#import <UserNotifications/UserNotifications.h>

Просмотреть файл

@ -1,6 +1,4 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. Licensed under the MIT license.
#pragma once

Просмотреть файл

@ -1,6 +1,5 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. Licensed under the MIT license.
#import <Foundation/Foundation.h>
#import "NotificationsViewController.h"

Просмотреть файл

@ -1,6 +1,4 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. Licensed under the MIT license.
#pragma once

Просмотреть файл

@ -1,6 +1,5 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. Licensed under the MIT license.
#import "RootViewController.h"
#import "LoginViewController.h"

Просмотреть файл

@ -1,6 +1,5 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. Licensed under the MIT license.
#pragma once

Просмотреть файл

@ -1,6 +1,5 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. Licensed under the MIT license.
#import <UIKit/UIKit.h>
#import "AppDelegate.h"