InbeaconSdk 3.4.01

InbeaconSdk 3.4.01

许可协议 NOASSERTION
发布最新发布2021年7月

Inbeacon 维护。



  • 作者:
  • Ronald van Woensel

文档

阅读完整的文档

基本实现

  • Resono inBeacon SDK 通过 CocoaPods 提供。要安装它,将以下行添加到您的 Podfile 中

     pod "InbeaconSdk", '~> 3.2'  
  • 从您的 Resono 账户页面 获取您的 client-IDclient-Secret,并使用这些凭据配置您的应用程序。

  • 添加 plist 项目

    隐私 - 总是使用位置描述 (NSLocationAlwaysUsageDescription)

    隐私 - 总是和当使用时使用位置描述 (NSLocationAlwaysAndWhenInUseUsageDescription)

    两者都应该包含一个鼓励用户启用“始终允许”的自定义入门文本。

如果没有这个,应用程序永远不会请求使用位置权限,SDK 也不会正常工作!

  • 编辑您的 AppDelegate.swift 或 AppDelegate.h/AppDelegate.m

AppDelegate.swift

import UIKit
import InbeaconSdk
import UserNotifications

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
	var window: UIWindow?
	
	func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
		
		// Fill in your credentials and initialize the SDK
		InbeaconSdk.createWith(clientId: "<your client-ID>", clientSecret:  "<your client-Secret")
		
		// make the AppDelegate also the delegate for UserNotifications
		UNUserNotificationCenter.current().delegate = self
		return true
	}

	func userNotificationCenter(_ center: UNUserNotificationCenter,didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
		if !InbeaconSdk.sharedInstance.didReceiveUserNotification(response.notification) {
			// your own usernotifications can be processed here..
			...
		}
		completionHandler()
	}

	func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
		completionHandler([.badge, .alert, .sound])
	}
}

AppDelegate.h

#import <UIKit/UIKit.h>
#import <inBeaconSdk/inBeaconSdk.h>
#import <UserNotifications/UserNotifications.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>
@property (strong, nonatomic) UIWindow *window;
@end

AppDelegate.m

#import "AppDelegate.h"

@interface AppDelegate ()
@end

@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *) launchOptions {

	// Fill in your credentials and initialize the SDK
	[InbeaconSdk createWithClientID: @"<your client-ID>" andClientSecret: @"<your client-Secret>"]; 
   
	// make the AppDelegate also the delegate for UserNotifications
	[UNUserNotificationCenter currentNotificationCenter].delegate = self;
    
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
         withCompletionHandler:(void (^)(void))completionHandler {
         
	if (![InbeaconSdk.sharedInstance didReceiveUserNotification: response.notification]) {
		// your own usernotifications can be processed here..
		...
	}
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
       willPresentNotification:(UNNotification *)notification
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {

	completionHandler(UNNotificationPresentationOptionSound | 
							UNNotificationPresentationOptionBadge | 
							UNNotificationPresentationOptionAlert );
}

@end