友盟推送获取简单的deviceToken

其实这只一个简单的获取deviceToken本身也只是提醒自己!

首先导入4个类库

UIKit.framework,CoreGraphics.framework,Foundation.framework,CoreLocation.framework

UMessage_Sdk_1.3.0需要拖入一个友盟第三方

下面一些获取deviceToken代码

#import "AppDelegate.h"
#import "UMessage_Sdk_1.3.0/UMessage.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   
    //设置 AppKey 及 LaunchOptions
    [UMessage startWithAppkey:@"自己申请的Appkey" launchOptions:launchOptions];
    
    //1.3.0版本开始简化初始化过程。如不需要交互式的通知,下面用下面一句话注册通知即可。
    [UMessage registerForRemoteNotifications];
    [UMessage setLogEnabled:YES];
    
    return YES;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    //1.2.7版本开始不需要用户再手动注册devicetoken,SDK会自动注册
    [UMessage registerDeviceToken:deviceToken];
    
   
    //用户可以在这个方法里面获取devicetoken
    NSLog(@"%@",[[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""]
                  stringByReplacingOccurrencesOfString: @">" withString: @""]
                 stringByReplacingOccurrencesOfString: @" " withString: @""]);
    
}


你可能感兴趣的:(友盟推送获取简单的deviceToken)