简体   繁体   English

如何在iPhone中以编程方式设置锁屏,壁纸和铃声?

[英]How to set lock screen , wallpaper and Ringtone programmatically in iPhone?

In iPhone can we set the lock screen, wallpaper and ringtone programmatically? 在iPhone中我们是否可以通过编程方式设置锁屏,壁纸和铃声?

If Yes , then please let me know how to set them? 如果 ,那么请告诉我如何设置它们?

This can all be done easily, but will be rejected by Apple. 这一切都可以轻松完成,但Apple会拒绝。

The ringtone can be changed by altering com.apple.SpringBoard.plist , specifically the ringtone key. 可以通过改变com.apple.SpringBoard.plist来更改ringtone ,特别是ringtone键。

The following code can be used to read the actual ringtone title of custom ringtones (synced by iTunes). 以下代码可用于读取自定义铃声的实际铃声标题(由iTunes同步)。

NSMutableDictionary *custDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/private/var/mobile/Media/iTunes_Control/iTunes/Ringtones.plist"];
NSMutableDictionary *dictionary = [custDict objectForKey:@"Ringtones"];

NSArray *keys = [dictionary allKeys];
id key = [keys objectAtIndex:indexPath.row];
NSMutableDictionary *customRingtone = [dictionary objectForKey:key];
NSString *name = [customRingtone objectForKey:@"Name"];
cell.textLabel.text = name;

The Wallpapers can be overwritten at: 壁纸可以覆盖:

NSString *homePath1 = @"/private/var/mobile/Library/SpringBoard/HomeBackground.jpg";
NSString *homePath2 = @"/private/var/mobile/Library/SpringBoard/HomeBackgroundPortrait.jpg";
NSString *lockPath1 = @"/private/var/mobile/Library/SpringBoard/LockBackground.jpg";
NSString *lockPath2 = @"/private/var/mobile/Library/SpringBoard/LockBackgroundPortrait.jpg";

These examples were used in one of my Cydia apps. 这些示例用于我的一个Cydia应用程序中。 Theres not really much more to them, but these should get you going in the right direction. 对他们来说并不是更多,但这些应该让你朝着正确的方向前进。

The answer by WrightsCS stopped working at some point due to a change in iOS. 由于iOS的变化, WrightsCS答案在某些时候停止了工作。 Unfortunately, this is something you have to live with if you wish to use undocumented features. 不幸的是,如果您希望使用未记录的功能,则必须使用此功能。

If you still need to do this, for non-App Store apps only , this code works in iOS 9.3. 如果您仍然需要这样做,仅适用于非App Store应用程序 ,此代码适用于iOS 9.3。 It could stop working in any future iOS release, though. 但它可能会在任何未来的iOS版本中停止工作。 (see comment below: no longer working in iOS 10) (见下面的评论:不再在iOS 10中工作)

#import "SBSUIWallpaperPreviewViewController.h"
#import <dlfcn.h>

// open the private framework dynamically
void *handle = dlopen("/System/Library/PrivateFrameworks/SpringBoardUIServices.framework/SpringBoardUIServices", RTLD_NOW);

UIImage *wallpaper = [UIImage imageNamed: @"background.jpg"];

Class sbClass = NSClassFromString(@"SBSUIWallpaperPreviewViewController");
// we create a view controller, but don't display it. 
//  just use it to load image and set wallpaper
SBSUIWallpaperPreviewViewController *controller = (SBSUIWallpaperPreviewViewController*)[[sbClass alloc] initWithImage: wallpaper];
[controller setWallpaperForLocations: 3];  // 3 -> set both for lock screen and home screen

dlclose(handle);

You'll need to add the private API header to your project. 您需要将私有API标头添加到项目中。 You can usually find these online with a little searching, for example, here . 您通常可以通过一些搜索在线找到这些, 例如,在这里

In the example above, [SBSUIWallpaperPreviewViewController setWallpaperForLocations:] is called with an argument of 3: 3 indicates the image should be used for both lock and home screens. 在上面的例子中, [SBSUIWallpaperPreviewViewController setWallpaperForLocations:]被调用的3参数:3表示图像应同时用于锁定和主画面。 1 indicates Lock screen only. 1表示仅锁定屏幕。 2 indicates Home screen only. 2表示仅主屏幕。


For an explanation of why I open this framework up dynamically , see my related answer here . 有关我动态打开此框架的原因的说明,请参阅此处的相关答案

I don't have an answer regarding ringtones . 我没有关于铃声的答案。 This really should be a separate question: completely different APIs at work. 这应该是一个单独的问题:完全不同的API在起作用。

如果你可以检查PLStaticWallpaperImageViewController请使用私有api

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM